按索引取值
name='yryriw 9999ndlaanl'
print(name[0])
print(name[-1])
y
l
切片:步长为正数,从左到右切片
print(name[0:7])
print(name[0:8])
print(name[0:7:2])
print(name[0::2])
print(name[-4::1])#将打印从倒数第四个字符到字符串末尾的所有字符
print(name[-4:-1:1])#顾头不顾尾,将打印从倒数第四个字符到倒数第一个字符之前的所有字符,不包括倒数第一个字符
print(name[-4:-1:-1])
print(name[-1:-4:-1])#如果步长为负数,则起始索引应该比结束索引大,这样切片操作才能从右向左提取子字符串。
yryriw
yryriw 9
yyi
yyi 99dan
aanl
aan
lna
长度len
print(len(name))
18
成员运算in|not in
print('999'in name)
print('irw'in name)
print('iw 9'in name)
print('iw9'in name)
True
False
True
False
移除空白strip:移除两端的空格
print(name.strip())
print(name.strip('lannel yryr'))
yryriw 9999ndlaanl
iw 9999nd
切分/割split
print(name.split())
print(name.split('yryr'))
['yryriw', '9999ndlaanl']
['', 'iw 9999ndlaanl']
循环
for i in name:
print(i)
print('*' * 50)
name_list=[1,2,3,4]
for i in name_list:
print(i)
y
r
y
r
i
w
9
9
9
9
n
d
l
a
a
n
l
**************************************************
1
2
3
4
标签:字符,内置,倒数,name,print,类型,字符串,9999ndlaanl,yryriw
From: https://www.cnblogs.com/nickyu511/p/17969269