Python provides powerful expression functions for use. The following describes the main expression operators:
1. +,-, * operator
There is nothing to say about these three operators, which can be used by elementary school students ......
2. "/", "//", "**" Operator
(1) "/" Operator
>>> 1/20 >>> 1.0/20.5 >>> 1.0/2.00.5 >>> 2.0/1.02.0 >>>
Have you found anything? "/" Is an integer division operator and the result is also an integer. However, for a floating point number, it is a division operator and the result is also a number of points. This is different from other languages in Python.
(2) "//" Operator
What is the "//" Operator Used?
>>> 1 // 20 >>> 2 // 12 >>>> 1.0 // 2.00.0 >>> 1 // 2.00.0 >>>>
"//" The operator is a real division operator in Python. the return value is an integer, regardless of the number of points or integer. However, the data type of the returned result is determined by the divisor and the divisor.
(3) "**" power operator
>>> 1 ** 21 >>> 2 ** 24 >>> 2 ** 38 >>> 2 ** 416 >>> 5 ** 53125 >>>
If you see the result, do you think it will be very convenient to perform a power operation in the future. Note the following:
>>>-2 ** 2-4> (-2) ** 24
-2 ** 2 does not show the expected result: 4 and the result is-4, because the power operator takes precedence over the unary operator, therefore, you must add parentheses to calculate the power of (-2) (-2) ** 2 = 4
(4) remainder operator for "%"
>>> 5% 32 >>> 4% 20 >>> 4% 31 >>> 4.0% 2.00.0 >>> 4.0% 3.01.0 >>>> 4.0% 5.04.0 >>> 2.75% 0.50.25 >>>