Python3:range()函数
来源:互联网 发布:成都网络推广培训 编辑:程序博客网 时间:2024/06/05 17:14
Python3:range()函数
- 转载请注明作者和出处:http://blog.csdn.net/u011475210
- 操作系统:WINDOWS 10
- 软件版本:python-3.6.2-amd64
- 编 者:WordZzzz
- Python3range函数
- Python2x中range函数
- Python3x中range函数
- 样例对比
Python2.x中range()函数:
老规矩,help!
>>> help(range)Help on built-in function range in module __builtin__:range(...) range(stop) -> list of integers range(start, stop[, step]) -> list of integers Return a list containing an arithmetic progression of integers. range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0. When step is given, it specifies the increment (or decrement). For example, range(4) returns [0, 1, 2, 3]. The end point is omitted! These are exactly the valid indices for a list of 4 elements.
可以看出,在Python2.x中,range()返回的是可以用来迭代的列表。
Python3.x中range()函数:
同样,help!
>>> help(range)Help on class range in module builtins:class range(object) | range(stop) -> range object | range(start, stop[, step]) -> range object | | Return an object that produces a sequence of integers from start (inclusive) | to stop (exclusive) by step. range(i, j) produces i, i+1, i+2, ..., j-1. | start defaults to 0, and stop is omitted! range(4) produces 0, 1, 2, 3. | These are exactly the valid indices for a list of 4 elements. | When step is given, it specifies the increment (or decrement).
啊哦,在Python3.x中,range()返回的是一个range对象。
样例对比:
Python2.x:
>>> range(1,10)[1, 2, 3, 4, 5, 6, 7, 8, 9]
Python3.x:
>>> range(1,10)range(1, 10)>>> list(range(1,10))[1, 2, 3, 4, 5, 6, 7, 8, 9]
通过list强制类型转换,可以在Python3.x中实现Python2.x中的range函数一样的效果。
系列教程持续发布中,欢迎订阅、关注、收藏、评论、点赞哦~~( ̄▽ ̄~)~
完的汪(∪。∪)。。。zzz
阅读全文
0 0
- Python3:range()函数
- python3 range函数
- python3 range() 函数和 xrange() 函数
- python3里面的range()函数
- python3中range函数的变化
- python3实现《机器学习实战》遇到的问题:range函数
- Python3 range()函数和numpy库函数:reshape用法
- python3实现《机器学习实战》遇到的问题:range函数
- python3 range 倒序
- python3 range 倒序
- range()函数
- range函数
- range()函数
- Python3:range生成数列用法
- Learning Python 018 Python2 和 Python3 中 range()函数的使用
- Python学习笔记:python3中的range()函数的返回对象类型
- Python学习笔记:python3中的range()函数的返回对象类型
- python3 函数
- matlab导入excel数据
- HDOJ HDU 1073 Online Judge
- Linux常用工具网址
- 选择,循环条件
- Jsp注释、小脚本、表达式、声明
- Python3:range()函数
- 什么是最小二乘法
- python集合运算
- What is the difference between call and apply?(关键词:call/apply/invoke)
- 【数据库】谈谈group by
- Gradle学习系列之九——自定义Task类型
- java的单线程,多线程
- 2017 ACM/ICPC Asia Regional Shenyang Online 1012 card
- Linux笔记_JAVA环境变量配置