首页
IT
登录
6mi
u
盘
搜
搜 索
IT
python字符串查找和引索
python字符串查找和引索
xiaoxiao
2023-03-24
3
s
=
'cheese'
#s赋值给字符窜cheese
print
(
s
.find(
'e'
))
#在s中查找e第一次所在的位置
print
(
s
.find(
'f'
))
#在s中查找f第一次出现的位置
print
(
s
.
index
(
'e'
))
#在s里查找e并打印所在位置
#print(s.index('f')) #这句不用注释,因为index就是找不到的时候抛出异常
打印结果: 2 #e在cheese中的第一次位置是2 -1 #f不在cheese中,所以结果为-1 2 #e在cheese中的第一个索引位置是2
转载请注明原文地址: https://ju.6miu.com/read-1202014.html
最新回复
(
0
)