字符串

>>> quest = ' what is your favorite color?'
>>> quest.capitalize
<built-in method capitalize of str object at 0x0000000002D71170>
>>> quest.capitalize()
' what is your favorite color?'
>>> quest.center(40)
'      what is your favorite color?      '
>>> quest.count('o')
4
>>> quest.endswith('r?')
True
>>> quest.fin

Traceback (most recent call last):
  File "<pyshell#34>", line 1, in <module>
    quest.fin
AttributeError: 'str' object has no attribute 'fin'
>>> quest.find('or',30)
-1
>>> quest.find('or',22)
26
>>> quest.index('or',1)
17
>>> quest.split()
['what', 'is', 'your', 'favorite', 'color?']
>>> quest.split('is')
[' what ', ' your favorite color?']
\
>>> quest.split('is')
[' what ', ' your favorite color?']
>>> quest.replace('your','my')
' what is my favorite color?'

python不支持直接修改字符子串,如quest[1]='a'是不合法的

你可能感兴趣的:(字符串)