[Python] 纯文本查看 复制代码 name = 'My name is Mike'
print(name[0])
'M'
print(name[-4])
'M'
print(name[11:14]) # from 11th to 14th, 14th one is excluded
'Mik'
print(name[11:15]) # from 11th to 15th, 15th one is excluded
'Mike'
print(name[5:])
'me is Mike'
print(name[:5])
'My na'
看一本python入门书 上面讲解 []标签的用法 其中 name = 'My name is Mike' 而 print(name[11:14]) 的结果是 'Mik'
11:14 指的是 从11开始到14之前的字段
而
word = 'friends'
find_the_evil_in_your_friends = word[0]+word[2:4]+word[-3:-1]
其中 word[2:4] 应该为 ri 但是print(find_the_evil_in_your_friends) 的结果竟然是 fiend 我算的应该是 frind才对呀 因为理论上 2:4是ri -3:-1 是nd才对啊
怎么到底是怎么算的 求解 尤其是[]中带有:号的情况下
|