Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What's the difference between Python3 and Python2?

Shulou Source: shulou.com Published: 2022-06-02 08:13:06 09月15日 Update

This article introduces what is the difference between Python3 and Python2. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

Compared with Python2, Python3:

1. Python3 removes the print statement and adds the print () function to achieve the same function.

2. The result of / in Python2 is an integer and a floating-point type in Python3.

3. The difference of string storage. Strings in python2 are stored as 8-bit strings, and strings in python3 are stored as 16-bit Unicode strings. The storage format has been upgraded.

4. The difference of value range. Xrange is used in python2 and range in python3. For example, the word xrange in python2 is changed to range in python3.

5. The difference of keyboard input. Enter a string from the keyboard, raw_input ("hello world") in python2 and input ("hello world") in python3.

6. Declare metaclass in Python2: _ metaclass_ = MetaClass, but declare metaclass in Python3:

Class newclass (metaclass=MetaClass): pass.

About what is the difference between Python3 and Python2 to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Characters strings storage use content more keyboard help yes same interest function function boy buddy article format floating point knowledge article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Redmi Microsoft Shulou Tech Info Xiaomi