python3 reversed(seq).py

"""
模块:python3 reversed(seq).py
功能:
参考:https://www.runoob.com/python3/python3-func-reversed.html
知识点:
1.reversed(seq)
返回一个反转的迭代器。
seq -- 要转换的序列,可以是 tuple, string, list 或 range。

2.reversed(seq) 和 sorted(iterable, key=None, reverse=False)的共同点:
是都不改变 传入的参数。
返回一个新的可迭代对象。
"""
s = 'Runoob'
print(list(reversed(s)))
# ['b', 'o', 'o', 'n', 'u', 'R']
t = ('R', 'u', 'n', 'o', 'o', 'b')
print(list(reversed(t)))
# ['b', 'o', 'o', 'n', 'u', 'R']
r = range(5, 9)
print(list(reversed(r)))
# [8, 7, 6, 5]
list1 = [1, 2, 4, 3, 5]
print(list(reversed(list1)))
# [5, 3, 4, 2, 1]
print(list1)
# [1, 2, 4, 3, 5]
发布了197 篇原创文章 · 获赞 61 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/weixin_42193179/article/details/104562686