Briefly describe the differences between Python2 and Python3

  • 2020-07-21 08:59:15
  • OfStack

Both Python2 and Python3 provide the print() method for printing information, but print differs slightly between the two versions

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.Python2 can print without parenthesis: print 'hello world', Python3 with parenthesis print("hello world")

3. In Python2, input requires the input string to be quoted. To avoid the behavior of reading a non-string type, raw_input() has to be used instead of input().

The differences between Python2 and Python3 are introduced as follows:

1. Normalization

1) In a large environment, Python2 contains the normative bad habits of PHP, Java, C and other languages. (Python is an open source language. Anyone can contribute code, but everyone uploads a different code specification.)

2), Python2 inside the repeated code is particularly much.

3) Python3 coding standard, clear, simple, in line with the purpose of Python.

2, coding

1) The default code of Python2 is ASCII, which can only display English, and error will be reported when displaying Chinese. For Python2 to display Chinese, add "# -* -ES58en: utf-8 -*-" on the first line.

2) Python3's default code is ES63en-8, which can be supported in Both Chinese and English.

3, grammar,

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

4. Data types

1) Python2 has both int type and long int type, while Python3 has only int type.

Pit of input in Python2


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

An error is reported when entering a string, and python3 solves this problem nicely.

conclusion

Above is the site to introduce Python2 and Python3 differences, I hope to help you, if you have any questions welcome to leave a message, this site will reply you in time!


Related articles: