python3 vs. python2
来源:互联网 发布:linux进程间通讯机制 编辑:程序博客网 时间:2024/06/06 12:34
哎一古,python3 和 python2为什么这么多不一样的地方,码一波碰到的不一样的地方,以下适用于0基础刚接触python的小白,比如我。
非常棒的博客: http://blog.csdn.net/samxx8/article/details/21535901
1. python2:print "xxx"
python3:print("xxx")
2. python2:sys.maxint
python3:
sys.maxsize
由于长整型和整型被整合在一起了,sys.maxint
常量不再精确。但是因为这个值对于检测特定平台的能力还是有用处的,所以它被Python 3保留,并且重命名为sys.maxsize
。
from sys importmaxint
from sys importmaxsize
a_function(sys.maxint)
a_function(sys.maxsize)
maxint
变成了maxsize
。- 所有的
sys.maxint
都变成了sys.maxsize
。
3. 当碰到这种报错的时候:TabError: inconsistent use of tabs and spaces in indentation
原因竟然是缩进不可用tab键敲出来的缩进,要用空格一个个敲出来,amazing
4. python2:import urlib2
python3:import urllib.request
5. python2:import 默认相对路径,python2缺省会搜索上一级目录、上上级目录 e.g. import releases
python3:import 默认绝对路径, e.g. from mlab import releases
某些情况 from xxx.yyy import zzz 看所属文件夹
6. python2:itertools.count(start).next()
python3:next(itertools.count(start))
- Python2.x vs Python3
- python3 vs. python2
- Python2 vs Python3: str
- Python2.x vs Python3——从 raw_input() 到 input()
- Python2 & Python3
- python3 与 python2区别
- python2.x ~ python3.x
- python2 python3语法区别
- python2/python3 name对照
- python2 和python3 共存
- python2 python3 部分区别
- 从python2到python3
- 学python2还是python3
- Python2还是Python3
- python2和python3注意事项
- Python2自动转Python3
- python2 和 python3比较
- Python3代码兼容Python2
- java的5种方法--九九乘法表
- JSP内置对象(上)
- 设计模式之单例模式
- Java的快速排序----在进程线程模拟实验中遇到的排序问题
- 常用数据库连接池 (DBCP、c3p0、Druid) 配置说明
- python3 vs. python2
- java通过JDBC链接SQLServer2017
- 使用DetachedCriteria 模糊查询中值为null时的情况
- mysql数据库数据类型之日期时间型
- java动态代理机制
- -bash: ls: command not found
- C#请写出代码判断一个整数是不是2的幂次方
- 习题6(6.15)
- JavaSpark-数据读存-JSON