python字符串
字符串含义
- python 3中的所有字符串是Unicode类型的
- 要用单引号('str')或者双引号("str"),三引号('''str''')定义字符串
- 字符串是不可变类型
定义一个字符串
>>>s = 'iloveyou'
字符串索引
字符串可以通过下标来访问元素
>>> s[3]
'v'
但不能修改元素,会引发TypeTypeError,例如:
s[2] = 't'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment