官网说明:Python 2 or 3区别

In summary : Python 2.x is legacy, Python 3.x is the present and future of the language

          
          
  1. Python 3.0 was released in 2008. The final 2.x version 2.7 release came out in mid-2010, with a statement of
  2. extended support for this end-of-life release. The 2.x branch will see no new major releases after that. 3.x is
  3. under active development and has already seen over five years of stable releases, including version 3.3 in 2012,
  4. 3.4 in 2014, and 3.5 in 2015. This means that all recent standard library improvements, for example, are only
  5. available by default in Python 3.x.
  6. Guido van Rossum (the original creator of the Python language) decided to clean up Python 2.x properly, 
  7. with less regard for backwards compatibility than is the case for new releases in the 2.x range. 
  8. The most drastic improvement is the better Unicode support (with all text strings being Unicode by default) as well as saner bytes/Unicode separation.
  9. Besides, several aspects of the core language (such as print and exec being statements, 
  10. integers using floor division) have been adjusted to be easier for newcomers to learn and to be more consistent with the rest of the language,
  11. and old cruft has been removed (for example, all classes are now new-style, "range()" returns a memory efficient iterable,
  12. not a list as in 2.x).

py2与3的详细区别

  • PRINT IS A FUNCTION

    The statement has been replaced with a print() function, with keyword arguments to replace most of the special syntax of the old statement (PEP 3105). Examples: 

         
         
  1. Old: print "The answer is", 2*2 
  2. New: print("The answer is", 2*2)
  3. Old: print x, # Trailing comma suppresses newline 【不换行】
  4. New: print(x, end=" ") # Appends a space instead of a newline 【不换行】
  5. Old: print # Prints a newline 【换行】
  6. New: print() # You must call the function!【换行】
  7. Old: print >>sys.stderr, "fatal error" 
  8. New: print("fatal error", file=sys.stderr)【标准错误】
  9. Old: print (x, y) # prints repr((x, y))
  10. New: print((x, y)) # Not the same as print(x, y)!

  • You can also customize the separator between items[定制分隔符], e.g.: 

         
         
  1. print("There are <", 2**32, "> possibilities!", sep="")

  • ALL IS UNICODE NOW

               
               
  1. 从此不再为讨厌的字符编码而烦恼

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

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


  • 某些库改名了

Old Name[pyton2]

New Name[pyton3]

_winreg

winreg

ConfigParser

configparser

copy_reg

copyreg

Queue

queue

SocketServer

socketserver

markupbase

_markupbase

repr

reprlib

test.test_support

test.support

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

琦彦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值