Briefly describe the differences between Python2 and Python3, and briefly describe python2python3

Source: Internet
Author: User

Briefly describe the differences between Python2 and Python3, and briefly describe python2python3

The print () method is provided in both Python2 and Python3 to print information. However, the print between the two versions is slightly different.

It is mainly reflected in the following aspects:

1. print in python3 is a built-in function with multiple parameters, while print in python2 is a syntax structure;

2. You can print 'Hello world' with no brackets during Python2 printing, and print ("hello world") with brackets in Python3 ")

3. In Python2, the input string must be enclosed by quotation marks. To avoid reading non-string-type behaviors, raw_input () must be used instead of input ()

The differences between Python2 and Python3 are described as follows:

1. Normative

1) In a large environment, Python2 contains bad practices in PHP, Java, C, and other languages. (Python is an open-source language. Anyone can contribute code, but the code specifications uploaded by each person are different .)

2) There are a lot of repeated code in Python2.

3) Python3 code is standardized, clear, and simple, and complies with Python's purpose.

2. Encoding

1) Python2 is encoded in ASCII by default and can only be displayed in English. If it is displayed in Chinese, an error is returned. To enable Python2 to display Chinese characters, add "#-*-encoding: UTF-8-*-" in the first line -*-".

2) The default encoding of Python3 is UTF-8, which is supported in both Chinese and English.

3. Syntax

1) User Interaction: the syntax of Python2 is "raw_input", while that of Python3 is "input ".

4. Data Types

1) In Python2, there are both int and long int types, while in Python3, There is only int type.

Input pitfall in Python2

print ("what do you like")a = input("Enter any content:")print ("i like",a)

An error is reported when the string is input, which is well solved in python3.

Summary

The above is the difference between Python2 and Python3 introduced by the small editor. I hope it will help you. If you have any questions, please leave a message. The small editor will reply to you in time!

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.