看海的猴 发表于 2020-6-22 09:13:15

列表倒序切片操作?

a = 形成新的列表 a = ["b", "a", "3"]

a =
a.reverse()
print(a)

请问还有哪几种方法可以倒着切片?

wp231957 发表于 2020-6-22 09:19:00

>>> a

>>> a[-3::-2]
['b', 'a', 3]
>>>

sunrise085 发表于 2020-6-22 09:19:10

print(a[-3::-2])
切片步长为负数就是倒着切片的

Twilight6 发表于 2020-6-22 09:19:47


这样呗:

a =
# a = ["b", "a", "3"]

print(a,a[-3::-2])

BIO-张磊 发表于 2020-6-22 09:20:31

a[-3::-2]

dasemimi 发表于 2020-6-23 06:52:51

厉害啊
页: [1]
查看完整版本: 列表倒序切片操作?