python2.0 和python3.0

发布时间:2019-08-22 08:02:36编辑:auto阅读(1755)

    python2.0 和python3.0区别
    1.官方解释:
       python2.0是过去的遗产;  
       python3.0是未来使用的。  (去繁从简)

    2.语法区别:
       python2.0    print "hello"
       python3.0    print ("hello")
       
    3.编码不同:
       python2.0    不能直接写中文;必须先声明utf-8  如:#-*- coding:utf-8 -*-
       python3.0    可以直接写中文,默认是unicode支持中文;不再烦恼字符编码问题。
       
    4.某些库改名了

        

    Old Name

    New Name

    _winreg

    winreg

    ConfigParser

    configparser

    copy_reg

    copyreg

    Queue

    queue

    SocketServer

    socketserver

    markupbase

    _markupbase

    repr

    reprlib

    test.test_support

    test.support


    还可以这样玩: (A,*REST,B)=RANGE(5)

       <strong>>>> a,*rest,b = range(5)
       >>> a,rest,b
       (0, [1, 2, 3], 4)
       </strong>


关键字