立即学习:https://edu.csdn.net/course/play/25498/304502?utm_source=blogtoedu
字符串可以用单引号、双引号或三引号引起来
反斜杠可以转义字符
常用字符串操作函数:
len()
replace()
index()
find()
split()
2**2 表示2的平方
2**3表示2的3次方
3种字符串拼接方式:
第一种:+号拼接
str = ' beijing ' + ' shanghai '
第二种:list拼接
list_str = [ 'ni','hao','bei','jing' ]
str2 = ' '.join(list_str)
第三种:format方式拼接
str = '我喜欢{},理由是{}' .format('python','简单')
#切片
s = '123456'
s[0:3] 表示从第0位取值,到第3位结束,包含第0位但是不包含第3位 即取头不取尾
s[:3] 等价于s[0:3] (简略的写法)
s[0:] 表示从第0位开始取值,一直取到最后
s[:-1] 表示从头开始取值,但是不包含最后一位
s[::2] 既没有起始点,也没有结束点,只有步长;表示从头开始一直到末尾,间隔2位取数