字符串的索引

所谓“下标”,就是编号

name = 'abcdef'
print(name[0])
print(name[1])
print(name[2])

 运行结果:

a
b
c
如果取出一部分,则可以在中括号[]中,使用:

name = 'abcdef'
print(name[0:3]) # 取 下标0~2 的字符
print(name[2:]) # 取 下标为2开始到最后的字符

 运行结果:

abc

cdef

 

posted on 2017-03-14 21:12  LoaderMan  阅读(206)  评论(0编辑  收藏  举报

导航