Today, I will show you the differences between the two versions of Python 2.7 and Python 3.7.
Difference 1: print syntax is used
Python2.7 print syntax is used >>> print "Hello Python"
Python3.7 Print syntax usage >>> print("Hello Python")
Example: Using double quotes to trigger the SyntaxError exception mechanism in Python 3.7.0 prompts Did you mean print("Hello Python3.7")
The difference between print and no line break
python 2.7 Use "," to print without line break
python 3.7 print without line breaks uses end=""
Difference 2: raw_input() and input()
Python 2.7 raw_input() and input() both exist and can be used. raw_input() receives a string. input() receives a number int /flot.
Python 3.7 raw_input() does not exist. Only input() exists. The two are combined and receive any Format returns string
Difference three: function cmp()
python 2.7 cmp(x,y) function is used For comparing two objects, if x y returns 1
python3.7 cmp() no longer exists, if you need To implement the comparison function, you need to introduce the operator module, which is suitable for any object
>>> import operator>>> operator.eq('hello', 'name');False>>> operator.eq('hello', 'hello');True
Difference four: string letter case string
string.letters: a string containing all letters (uppercase or lowercase)
In Python 3.0, string.ascii_letters.
[Recommended course: Python column course]
The above is the detailed content of The difference between Python 2.7 and Python 3.7. For more information, please follow other related articles on the PHP Chinese website!