Python reversed() 函数
定义和用法
reversed() 函数返回反向的迭代器对象。
实例
反转列表的顺序,并打印每个项目:
alph = ["a", "b", "c", "d"] ralph = reversed(alph) for x in ralph: print(x)
语法
reversed(sequence)
参数
| 参数 | 描述 |
|---|---|
| sequence | 必需。可迭代对象。 |
相关页面
参考手册:iter() 函数(返回迭代器对象)
参考手册:list.reverse() 方法(反转列表)