Python3 reversed 函数

 Python3 内置函数


描述

reversed 函数返回一个反转的迭代器。

语法

以下是 reversed 的语法:

reversed(seq)

参数

  • seq -- 要转换的序列,可以是 tuple, string, list 或 range。

返回值

返回一个反转的迭代器。


实例

以下展示了使用 tuple 的实例:

实例

#!/usr/bin/env python3 # 字符串 seqString = 'Runoob' print(list(reversed(seqString))) # 元组 seqTuple = ('R', 'u', 'n', 'o', 'o', 'b') print(list(reversed(seqTuple))) # range seqRange = range(5, 9) print(list(reversed(seqRange))) # 列表 seqList = [1, 2, 4, 3, 5] print(list(reversed(seqList)))

以上实例输出结果为:

['b', 'o', 'o', 'n', 'u', 'R']
['b', 'o', 'o', 'n', 'u', 'R']
[8, 7, 6, 5]
[5, 3, 4, 2, 1]

Python3 reversed 函数的更多相关文章

  1. python3 reversed() 函数笔记

    需要逆向循环序列的话,先正向定位序列,然后调用 reversed() 函数. for i in reversed(range(1, 10, 2)):        print(i) 97531

  2. Python3 isinstance() 函数

    Python3 isinstance() 函数 描述 isinstance() 函数来判断一个对象是否是一个已知的类型,类似 type(). isinstance() 与 type() 区别: typ ...

  3. Python3 join函数和os.path.join用法

    Python3  join函数和os.path.join用法 os.path.join()连接两个文件名地址的时候,就比os.path.join("D:\","test. ...

  4. Python3 round() 函数

    Python3 round() 函数  Python3 数字 描述 round() 方法返回浮点数x的四舍五入值. 语法 以下是 round() 方法的语法: round( x [, n] ) 参数 ...

  5. Python3 range() 函数用法

    Python3 range() 函数用法  Python3 内置函数 Python3 range() 函数返回的是一个可迭代对象(类型是对象),而不是列表类型, 所以打印的时候不会打印列表. Pyth ...

  6. Python3 chr() 函数

    Python3 chr() 函数 Python3 内置函数 描述 chr() 用一个整数作参数,返回一个对应的字符. 语法 以下是 chr() 方法的语法: chr(i) 参数 i -- 可以是 10 ...

  7. Python3 tuple 函数

    Python3 tuple 函数  Python3 内置函数 描述 tuple 函数将列表转换为元组.. 语法 以下是 tuple 的语法: tuple( seq ) 参数 seq -- 要转换为元组 ...

  8. Python3 bytes 函数

    Python3 bytes 函数  Python3 内置函数 描述 bytes 函数返回一个新的 bytes 对象,该对象是一个 0 <= x < 256 区间内的整数不可变序列.它是 b ...

  9. Python3 pow() 函数

    Python3 pow() 函数  Python3 数字 描述 pow() 方法返回 xy(x的y次方) 的值. 语法 以下是 math 模块 pow() 方法的语法: import math mat ...

随机推荐

  1. Mapperreduce的wordCount原理

    wordcount原理: 1.mapper(Object key,Object value ,Context contex)阶段 2.从数据源读取一行数据传递给mapper函数的value 3.处理数 ...

  2. eclipse插件spket安装

    1.

  3. groovy 从jsonList中读取某个字段

    今天又被groovy的高效吓到了. 想提取所有的itemCodes,两种玩法 一.常规方法:遍历组装 RestResult items = getListPager() def temp = [] i ...

  4. git 每次push都需要输入用户和密码

    git remote -v origin https://github.com/userName/xx.git (fetch) origin https://github.com/userName/x ...

  5. genymotion使用学习

    1 安装 直接去其官网(https://www.genymotion.com/#!/download)下载安装包安装即可,安装中会附带安装VirtualBox. 2 注册 必须使用帐号登录后,方可下载 ...

  6. pytest 单元测试

    pytest简介 pytest 是python的一种单元测试框架,它非常的简洁.清晰. pytest 安装 pip install -U pytest 查看pytest版本 pytest --vers ...

  7. FMS Dev Guide学习笔记(SharedBall)

    一.开发交互式的媒体应用程序1.共享对象(Shared objects) ----SharedBall example 这个SharedBall example创建了一个临时的远程共享对象.类似于多人 ...

  8. 吴裕雄 python 机器学习-DMT(2)

    import matplotlib.pyplot as plt decisionNode = dict(boxstyle="sawtooth", fc="0.8" ...

  9. 吴裕雄 oracle PL/SQL编程

  10. 吴裕雄 03-mysql连接

    mysqli_connect(host,username,password,dbname,port,socket);参数 描述host 可选.规定主机名或 IP 地址.username 可选.规定 M ...