This article mainly introduces some special division and power operations in Python. what about division? "*" Is a multiplication operation. what about this? This article explains the differences between these operations. For more information, see what languages do not support addition, subtraction, multiplication, division, and division algorithms. But do you know what operations these symbols represent in Python?
"/" Is a division operation. what about? "*" Is a multiplication operation. what about this? Next we will introduce them one by one.
"//" Operation
The division operator is "/", which is a human operator, but the result of the binary operator "/" is determined by the operand itself, for example:
The code is as follows:
20/3
6
20/3 .0
6.666666666666667
20.0/3
6.666666666666667
20.0/3.0
6.666666666666667
That is to say, when the "/" operator is used, if one of the operands is a floating point number, the result is a floating point number. We call it a real division, but if both operands are integer numbers, the result is an integer that gives away decimal places. this is called Division. However, in this case, no matter whether the operand is an integer or a floating-point number, all the results I want are divisible, then "//" will be used, this "//" is used to solve this problem.
"//" Starts with Python2.2. in addition to "/", the division operator introduces a division operator, which is only used for division. The example is as follows:
The code is as follows:
20 // 3
6
20 // 3.0
6.0
20.0 // 3
6.0
20.0 // 3.0
6.0
20 // 3.00
6.0
Regardless of the operand, the result of "//" is an integer division. if the operand is a floating point number, the result returned to us is a integer converted to a floating point number.
"**" Operation
This "**" is relatively simple, namely the power operation of Python in the title. The example is as follows:
The code is as follows:
2 ** 0
1
2 ** 1
2
2 ** 10
1024
2 ** 20
1048576
The first operand is the base number, and the second operand is the index.
End ~