1. 程式人生 > >Python字符串相關操作

Python字符串相關操作

cal pos better mmu ace ant all lac string

字符串操作練習:

>>> ‘\‘No!\‘,Tom didn\‘t want to join them. ‘ #使用斜杠來避免引號沖突
"‘No!‘,Tom didn‘t want to join them. "
>>> ‘abc‘*3
‘abcabcabc‘
>>> words = ‘Let\‘s make the world a better place!‘
>>> len(words)
36
>>> words[35]
‘!‘
>>> words[20:33]
‘ a better pla‘
>>> words[-10:]
‘ter place!‘
>>> words[1]=‘D‘ #String is immutable
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: ‘str‘ object does not support item assignment

Python字符串相關操作