python common arithmetic operators, comparison operators, bitwise logical operators

Edit Time: 2019-09-04,22: 58: 49

Arithmetic operators

  • '+', '-', '*', '/': addition, subtraction, multiplication, and division
  • '**': exponentiation, '@': divisible, '%': Remainder Number
= 15 NUM_1; =. 7 NUM_2 Print (NUM_1 NUM_2 +)   # plus the output 22 is Print (NUM_1 * NUM_2)   # multiplier output 105 Print (NUM_1 / NUM_2)   # addition to the output 2.142857142857143 Print (NUM_1 ** 2)   # exponentiation output 225 Print (NUM_1 // NUM_2)   # divisible output 2 Print (NUM_1 NUM_2%)   # modulo output 1






  Introducing numerical calculation math module:

 

pi PI       pow (x, y) Calculating power of y x
e Scientific constants   fmod(x, y) Calculate x% y
ceil(x) Rounding up to an integer   hypot (x, y) sqart(x*x +  y*y)
floor(x) Rounded down to an integer   gcd(a, b) Returns a, b greatest common divisor
exp(x) Returns e ** x   isnan(x) Determining whether the non-data type, True indicates NaN
sqrt(x) x square root of arithmetic   isinf(x) Determine whether the infinite value, True representation Inf

 

Comparison Operators

 

> more than the
< Less than
>= greater or equal to
<= Less than or equal
== equal
!= not equal to

 

Logical Operators

 

and versus
or or
not

non-

  • And short-circuit: A and B, when the operands A is False, then the B operand is not performed (is short-circuited), the output of False
  • Or short circuit: A and B, if operand A is True, then the B operand is not performed (is short-circuited), the output True

Bitwise Operators

 

& Bitwise AND
|    Bitwise or
^ Bitwise exclusive or (two different operand returns 1)
~ Bitwise

 

three = 3; eight = 8
# 当操作数为非布尔值时,返回操作数
print(three and eight)  # 输出 8
print(eight and three)  # 输出 3
print(three or eight)  # 输出 3
print(eight or three)  # 输出 8

num = 15
print((num % 2 == 0) and (num % 3 == 0))  # 短路与(第一个操作数为False时,第二个操作数将不会执行) 输出 False
print((num % 3 == 0) or (num % 2 == 0))  # 短路或(第一个操作数为True时,第二个操作数将不会执行) 输出 True

 

Guess you like

Origin www.cnblogs.com/exploer/p/11461387.html