The difference between the Pyhon2 and Python3 of the knowledge point worth 200 dollars

Source: Internet
Author: User

The difference between P2 and P3
-Encode & string:
String:
P2:
Unicode v = U ' find the table ' is intrinsically stored in Unicode (Universal code)
(str/bytes) v = ' Find the table ' essence is stored in bytes
Py3:
str v = ' Find the table ' is essentially Unicode (universal code)
Bytes v = B ' find the table ' is essentially a byte store

Coding:
P2
-ASCII
File header can be modified #-*-encoding:utf-8-*-

P3:
'-utf-8
File header can be modified: #-*-encoding:utf-8-*-

Inheritance
P2: Classic class/New class
P3: New Class

The difference between using super ()
P2: A base class must be added to the actual parameters
P3: can be used directly without parameter calls

Range
P2:range/xrange
P3:range

Input
PY2:V1 = raw_input (' Please enter user name ')
Py3:v2 = input (' Please enter user name ')

Print
Py2:print ' xxxxx '
Py3:print (123)

-1/2 Results
P2: return 0
P3: Returns 0.5 without the difference between int and long

-true and False
Py2:true and False are two global variables in py2, which can be assigned values or other operations, with initial values of 1 and 0, respectively.
Although the modification violates Python's design principles, it is true that you can change

PY3: Modified this variable to make true and flase immutable


-Iterators
Py2: Many of the methods that return a list, such as range, the Dictionary object's Dic.keys (). Dic.values () method, Map\filter\zip;
And the iterator must implement the next method

Py3: Changed the method of returning the list to return iteration object, built-in __next__, do not need to implement next

-nonlocal
Py2: There is no way to declare the edge wave as a non-local variable in the nested function, only the function can find that declaration global variable

The Pye3:nonlocal method can be implemented

The difference between the Pyhon2 and Python3 of the knowledge point worth 200 dollars

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.