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