python3和python2语法区别

1、print

python2中是print xxx

python3中是print(xxx)

2、抛异常except

python2中except Exception,e:

      print "Exception别名是e”

python3中except Exception as e:

      print ("Exception别名是e”)

3、urllib模块

python2中import urllib2

python3中import urllib3    因为python3中将python2中的urllib和urllib2两个库合并为一个urllib,所以python3中无法安装urllib2,如果需要可以安装第三方库urllib3

4、input()

python2中是 raw_input() 

python3中是 input()

5、os.system()

python3中是os.system("cls")

python2中是os.system('clear')  clear再在python3中运行会报clear不是内部或外部命令

6、urlparse

python2中是import urlparse

python3中是from urllib.parse import urlparse

原文地址:https://www.cnblogs.com/mihoutao/p/12915604.html