Python核心编程(切片索引的更多内容)

# coding=utf8

s = 'abcde'
i = -1

for i in range(-1, -len(s), -1):
    print(s[:i])

# 结果
'''
abcd
abc
ab
a
'''
原文地址:https://www.cnblogs.com/lqcdsns/p/6041940.html