目录
1.python2 和python3的print区别
# python2:
print "hello"
# python3:
print("hello")
2.python2和python3中input的区别
# python2 input解析为int 型, raw input 为str类型
input()
# python3 input解析为str型
input()
3.python2 和 python3中range的区别
# python2:
xrange()
# python3:
range()
4.python2 和python3中除法的区别
python2的除法:和c语言类似,两个整数相除的结果一定是整数,除数与被除数有一个是浮点数,结果就是浮点数。
(貌似从2.7开始,python2的除法就和python3一样了,反正2.6.4是不行的)
# Python2:
121/4=30
# Python3:
121/4=30.25
要想python2实现和python3一样的效果,两种方法可行(2.6.4版本测试通过)。
1.导入division 模块
from future import division
2.使用浮点数参与计算。
num=121/4.0
5.python2 和python3中字典方法的区别
确定key 是否存在于字典中,返回True 或Flase
# python2:
dict.has_key(key)
# python3:
in 或 not in
6.python2 和python3不等于号的区别
# python2:
<>
# python3:
!=