庄泽波の博客

好记性不如烂笔头

What's New In Python 3.X

    As Python updating to python 3.6, its performance is better than Python 2.x, which is

good news to every Python developer. I would like to write down new features of Python 3.x,

I hope it can help me remind the history of Python development.

 

1.Python 3.0

1.1 Print Function.

     We need to add bracket when invoking the print() function in Python.

1.2 Views And Iterators Instead of List.

     dict methods dict.keys(), dict.items(). dict.values() return views instead of lists. For example, 

 keys = d.keys(); keys.sort()

  this no longer works. Use k = sorted(d) instead.

    map() and filter() return iterators.

    range() behaves like xranges() but the latter no longer exists.

    zip() return iterators.

1.3 Ordering Comparisons

   The ordering comparison operators (<, <=, >=, >) raise a TypeError exception when the operands

do not have a meaningful natural ordering. (1 < '', 0 > None order len <= len are no longer valid.)

   builtin.sorted() and list.sort() no longer accept the cmp argument providing a comparison function.

Use the key argument instead.

   The cmp() function should be treated as gone, as the __cmp__() special method is not longer supported.

   

posted on 2017-02-14 13:03  庄泽波  阅读(171)  评论(0编辑  收藏  举报

导航