- str1="123212"
- str2="abc"
- print("position of 2 in string 1:",str1.index('2'))
- print("how many 2s are there in string 1:",str1.count('2'))
- print("string 1 contains 3:",'3' in str1)
- print("string 1 contains 5:",'5' in str1)
- print("string 1 does not contain 5",'5' not in str1)
- str1+=str2
- print("concatenate str1 and str2:",str1)
- str2*=3
- print("copy the content of string 2 3 times:",str2)
複製代碼 |