python学习---python2与python3的区别

python2与python3的区别

1、python2.x和python3.x的最大区别是编码(Unicode),代表python3里面可以默认直接写中文了。

2、print的用法:

  python2的写法:print 'zwt'

  python3的写法:print('zwt')   也就是python3里必须要加括号,不然会报错

3、input的用法:

  python2的写法:username=raw_input('username:')    在python2中不建议用input,会引起一些麻烦。

  python3的写法:username=input('username:')     input主要用于python3中与用户交互     

3、某些库名的修改

Old Name New Name
_winreg winreg
ConfigParser configparser
copy_reg copyreg
Queue queue
SocketServer socketserver
markupbase _markupbase
repr reprlib
test.test_support test.support

 4、Twisted(for networking and other applications)不支持python3,

  Twisted是非常强大的异步网络框架,强大到它进行重构了ftp、smtp、dns、http等一些网络协议。异步的意思就是单线程下比多线程还要快。

原文地址:https://www.cnblogs.com/ommph/p/11361887.html