字符串的索引和切片

索引:
msg='hello world'
正向取
a=msg[1]
反向取
b=msg[-1]
ps:只能取不能改

切片:
msg='hello world'
res=msg[0:5](hello)
切片的步长:
res=msg[0:5:2](hlo)
反向步长:
res=msg5:0:-1

ps:成员运算也可以用在字符串中

posted @ 2020-03-10 19:29  江湖有梦  阅读(706)  评论(0编辑  收藏  举报