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. leetcode1007

    public class Solution { public int MinDominoRotations(int[] A, int[] B) { var na = A.Length; var nb ...

  2. Oracle 表复杂查询之多表合并查询

    转自:https://www.cnblogs.com/GreenLeaves/p/6635887.html 本文使用到的是oracle数据库scott方案所带的表,scott是oracle数据库自带的 ...

  3. golang执行shell命令

    ommand := "echo hello” cmd := exec.Command("/bin/bash", "-c", command) byte ...

  4. centos7 Apache 2.4.6 多域名多网站配置

    Apache 2.4.6 多域名多网站配置 在/etc/httpd/conf 下 编辑 vim httpd.conf 添加:ServerName 外网IP 并注释 #DocumentRoot &quo ...

  5. APP-8.1-百度语音应用

    1.百度语音登录地址 http://yuyin.baidu.com/ 2.控制台创建应用 3.生成签名 3.1Postman软件应用 APP-8.2-Postman应用 3.2Postman执行 UR ...

  6. Raft算法和Gossip协议

    简单介绍下集群数据同步,集群监控用到的两种常见算法. Raft算法 raft 集群中的每个节点都可以根据集群运行的情况在三种状态间切换:follower, candidate 与 leader.lea ...

  7. 跨域(一)——CORS机制

    Ajax是严格遵守同源策略的,既不能从另一个域读取数据,也不能发送数据到另一个域.但是,W3C的新标准中CORS(Cross Origin Resource Sharing)推进浏览器支持这样的跨域方 ...

  8. 拓展Scene视图——场景编辑Vector2/3

    Test.cs using System.Collections; using System.Collections.Generic; using UnityEngine; public class ...

  9. 【373】LabelEncoder 相关

    OneHotEncoder独热编码和 LabelEncoder标签编码 pandas.DataFrame.groupby

  10. wx小程序获取组件属性数据data-prop

    在微信小程序中有时会在组件上定义一些属性,使用data-来定义 <view data-idvalue="id" data-Index-Name="IndexName ...