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,
1 | 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.
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步