Environment: python3.x
A, B = 60,164
One, arithmetic operators
Operator |
Describe |
Example |
+ |
Addition |
A+b = 224 |
- |
Subtraction |
A-B =-104 |
* |
Multiplication |
A*b = 9840 |
/ |
Except (keep decimal digits) |
60/2 = 30.0 |
// |
Divisible |
60//2 = 30 |
% |
Seeking redundancy |
B%a = 44 |
** |
Powers |
a**2 = 3600 |
Second, comparison operator (returns TRUE or false)
Operator |
Describe |
Example |
== |
Determine if values are equal on both sides |
A = = B False |
! = |
Determine if values are not equal on both sides |
A! = B True |
> |
Determine if the left value is greater than the right |
A > B False |
< |
Determine if the left value is less than the right |
A < b True |
>= |
Determine if the left value is greater than or equal to the right |
A >= b False |
<= |
Determine if the left value is less than or equal to the right |
A < b True |
Three, assignment operators
Operator |
Describe |
Example |
= |
Assign value |
c = 30 |
+= |
Add and assign values |
c+=10 equivalent to C=c+10 |
-= |
Subtract and assign values |
c-=10 equivalent to C=c-10 |
*= |
Multiply and assign values |
c*=10 equivalent to C=c*10 |
/= |
Divide and assign values |
c/=10 equivalent to C=c/10 |
//= |
Divide and assign values |
c//=10 equivalent to C=c//10 |
%= |
Finding the remainder and assigning values |
c%=10 equivalent to C=c%10 |
**= |
exponentiation and assign values |
C**=3 equivalent to c = = C**3 |
Four, bitwise operators
A = #0011 1100
b = 164 #1010 0100
Operator |
Describe |
Example |
& |
Bitwise AND: Only true when True (1) |
A&b 0010 0100 |
| |
Bitwise OR: Only false when the same is False (0) |
A|b 1011 1100 |
^ |
Bitwise XOR: Same as 0, opposite 1 |
A^b 1001 1000 |
<< |
Bitwise left shift n bit : 2 n sub-square |
A << 1 0111 |
>> |
Bitwise RIGHT SHIFT n bit : 2 n sub-square |
A >> 2 1111 |
~ |
Bitwise inverse: |
The negative number is in the complement, such as this column: ~a for 1111 1111 1111 1111 1111 1111 1100 0011( on the machine) to get the complement, anti-code:1111 ... 1100 0010(complement -1), the original code (anti-code inversion):1000...0011 1101 (The first bit is the sign bit) Get the result -61 |
Five, logical operators
Operator |
Describe |
Example |
and |
Logic and |
A and B are true output b(the last value), false output False value |
Or |
Logical OR |
A or B is true output truth, false output b(i.e. the last value) |
Not |
Logical Non- |
Not a False |
VI. member Operators
Inch
Not in
Such as
list = [' A ', ' B ']
' A ' in list = True #判断是否为该list成员, relative to
Vii. Identity Arithmetic
Is
Not is
Such as
A = 1
b = A
B is a = "True #is判断两个标识符是不是指向同一对象, corresponds to not" is
Eight or three-dollar operation
result = value 1 if condition else value two
such as: A,b,c = 1,3,5
D=a if a>b else C #如果a >b d=a, otherwise d=c,
Print (d)
D=a if a<b else C # #如果a <b is d=a, otherwise d=c
Print (d)
Python basic operations