字符串String
字符串
>>> s = 'hello, '
>>> s[0] # 索引
'h'
>>> s[1:3] # 分片
'el'
>>> s + 'world' # 加法
'hello, world'
>>> s * 2 # 乘法
'hello, hello, '>>> s = 'hello'
>>> s[1] = 'ab' # 不能对它进行赋值
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignmentfind
split
join
strip
replace
translate
lower/upper
小结
参考资料
Last updated