Introduction to division and power operations in Python, and Division operations in python
No matter what language, you can't do without the addition, subtraction, multiplication, division algorithms. But in Python, do you know what operations these symbols represent?
"/" 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:
Copy codeThe 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:
Copy codeThe 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:
Copy codeThe 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 ~