python2和python3的区别整合
-
用户输出:print
-
python2中是一个命令,而在python3中是一个函数。
-
print 'hello world' #2 print('hello world') #3 print('hello world',sep="") #3
-
-
用户输入:input
-
ret = input() #2 接收的是数字,不然的话是不合法的 ret = raw_input() #2 返回值是str ret = input() #3 返回值是str
-
-
默认编码
- python2:ASCII
- python3:utf-8
-
字符串类型
- python2
- str和unicode
- str -> unicode
- python3
- str和byte
- str - > byte:encode()
- byte -> str: decode()
- python2
-
range
- python2中有range和xrange
- range返回list类型
- xrange放回xrange对象:是一个类似迭代器的可惰性求值的
- python3
- range返回range类型
- python2中有range和xrange
-
不等于符号
- python2:<>,!=
- python3:!=