New features of Python3.0

Online article about the difference Python3 and Python2 are rotten Street, but basically copy to copy, in order to trace the origin, directly Tell me what network the most likely, the official website of structured documents stronger.
This article is Python3.0 official website Documentation What's New In Python 3.0 summarized. Published Python3.0 looked at, even in 2008, has more than 11 years, I rub,
for developers, Py2 with distinction Py3 little difficult is that many libraries have to follow the upgrade right now, absolutely most library should have the support Py3

1. Data Type

1. Integer

  1. Remove long type, leaving only int, int represents the range unlimited, fast hardware
  2. 1/2 returns to float, rather than int, using 2 // returns the integer 1, and is in addition to the floor, not round

2. String

  Str and is divided into bytes, it is Unicode str, also the default encoding bytes is a particular encoding, such utf-8 and the like. You may be used str () method to other types (e.g., integer) data types into a string str.

2. Views and Iterators instead of Lists

  1. dict.keys (), dict.items (), dict.values ​​() returns view, no longer returns list
  2. map (), filter () Returns the iterator, no longer returns list
  3. range () ibid.
  4. zip () ibid.

3. The classes are new class

Class definition as follows, inherited from the default object class, of course, you explicitly inherit the object class is not a problem

class Student:
    def __init__(self, name):
        self.name = name

4. print () function is

print('hahaha') # 必须加()

Guess you like

Origin www.cnblogs.com/ajianbeyourself/p/11969667.html
Recommended