Python3与Python2主要差异
1 语法变化
最重要的变化内容
1. print 语句被 Python3 废弃,统一使用 print 函数
2. exec 语句被 python3 废弃,统一使用 exec 函数
3. execfile 语句被 Python3 废弃,推荐使用 exec(open("./filename").read())
4. 不相等操作符"<>"被 Python3 废弃,统一使用"!="
5. long 整数类型被 Python3 废弃,统一使用 int
6. xrange 函数被 Python3 废弃,统一使用 range,Python3 中 range 的机制也进行修改并提高
了大数据集生成效率
7. 迭代器 iterator 的 next()函数被 Python3 废弃,统一使用 next(iterator)
8. raw_input 函数被 Python3 废弃,统一使用 input 函数
9 字典变量的 has_key 函数被 Python 废弃,统一使用 in 关键词
10. file 函数被 Python3 废弃,统一使用 open 来处理文件,可以通过 io.IOBase 检查文件类型
11. apply 函数被 Python3 废弃
12. 异常 StandardError 被 Python3 废弃,统一使用 Exception