This article lists the differences between Python 2 and Python 3. This is an incomplete list and will be replenished gradually in the future.
1. Print output
Suppose you want to output "HI", let's look at Python 2 and Python 3 in their own notation. The Python 2 notation
Here are two ways to use it.
Print "HI"
Print ("Hi") Python 3 notation
Only one way of writing can be used.
Print ("Hi") 2 input
Let's say you want to enter the number 289 into the variable n, we'll look at Python 2 and Python 3 in their respective ways. the Python 2 notation
There are two ways of writing. The first one is:
Nstr = Raw_input ("Enter a number:") #输入提示 (that is, "Enter a number:") you wrote it.
n = Int (nstr) #raw_input () receives a string, which converts it to an integer
The second formulation is:
n = input ("Enter a number:") the writing of Python 3
The wording is:
NSTR = Input ("Enter a number:") #输入提示 (that is, "Enter a number:") is written by you
n = Int (nstr) #raw_input () receives a string, which converts it to an integer
In fact, Python 3 's input () completes the function of Python 2 's raw_input (). Python 3 does not have the raw_input () function. 3. Divide
Suppose you want to calculate 9 divisible by 2 and store the quotient in variable N. Python 2 and Python 3 are written in a different notation. the Python 2 notation
n = 9/2 #两个整数相除, and the result is the integer Python 3 notation
n = 9//2 #注意有两个斜杠
and the wording:
n = 9/2
The result is 4.5, which is counted as floating-point division.