Python 字符串的负索引

负索引

使用负索引从字符串末尾开始切片:

实例

从字符串末尾开始计数,获取从位置 5 到位置 1 的字符:

b = "Hello, World!"
print(b[-5:-2])

亲自试一试