"Python Basics" the difference between Python 2 and Python 3

Source: Internet
Author: User
the difference between Python 2 and Python 3 recently began to learn Python, the process of continuous learning to the difference between the two, in order to facilitate the review, so write here, the content will be constantly updated

1, Encoding: Python2 's default encoding is ASCII, so the default is not supported in Chinese, if you want its support must add #-*-Coding:utf-8-*-and Python3 's default encoding is Utf-8, that is, in writing Python can be directly used in text;

2. A clearer distinction is made between text and binary data in Python3, text is always Unicode, represented by the STR type, binary data is represented by the bytes type, and Python3 does not mix str and bytes in any implicit way, So you can't stitch strings and byte packets, or search for strings in a byte packet (or vice versa), or pass a string into a function with a byte packet (or vice versa);

3, Python 2.x to 2020 will no longer have the support of the official website;

4, Python 2 of the input raw_input was deleted, using input to replace;

5. The print statement in the Python2 is deleted and replaced with the print () function;

6. In Python2 socket, between the server and the client can transmit strings, in the Python3 can only transfer binary encoding, so for STR to carry out encode () operation;



Related Article

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.