Python基础——字符串索引

  • A+
所属分类:Python

正向索引

s = "PYTHON"
>>>s[0]
'P'

反向索引

>>>s[-6]
'P'
Python基础——字符串索引

区间索引

[A:B]
从位置A到位置B的部分字符串,不包含位置B

>>>s[-6:-1]
'PYTHO'
#拿到末位
>>>s[-6:]
'PYTHON'

zore

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: