Operator |
Name |
Description |
Example |
+ |
Add |
Add two objects |
3 + 5 gets 8. ' A ' + ' B ' gets ' ab '. |
- |
Reducing |
Get negative numbers or a number minus another number |
-5.2 Gets a negative number. 50-24 get 26. |
* |
By |
Multiply two numbers or return a string that is repeated several times |
2 * 3 get 6. ' La ' * 3 gets ' Lalala '. |
** |
Power |
Returns the Y-power of X |
3 * * 4 gets 81 (ie 3 * 3 * 3 * 3) |
/ |
Except |
x divided by Y |
4/3 gets 1 (the integer division gets the integer result). 4.0/3 or 4/3.0 get 1.3333333333333333 |
// |
Take the Divide |
The integer part of the return quotient |
4//3.0 gets 1.0 |
% |
Take the mold |
Returns the remainder of a division |
8%3 got 2. -25.5%2.25 got 1.5. |
<< |
Move left |
Shifts a number of bits to the left a certain number (each number in memory is represented as a bit or binary number, i.e. 0 and 1) |
2 << 2 get 8. --2 is expressed as 10 by bit |
>> |
Move right |
Move a number of bits to the right by a certain number |
One >> 1 get 5. --11 is expressed as 1011 by bit, 1 bits to the right and 101, or 5 in decimal. |
& |
Bitwise AND |
The bitwise of number and |
5 & 3 Get 1. |
| |
by bit or |
Number of bitwise OR |
5 | 3 Get 7. |
^ |
Per-bitwise XOR OR |
The bitwise XOR of the number or |
5 ^ 3 Get 6 |
~ |
Flip by bit |
The bit flip of X is-(x+1) |
~5 got 6. |
< |
Less than |
Returns whether x is less than Y. All comparison operators return 1 to represent true, and 0 to represent false. This is equivalent to the special variable true and false respectively. Note that these variable names are capitalized. |
5 < 3 returns 0 (that is, false) and 3 < 5 returns 1 (that is, true). Comparisons can be any connection: 3 < 5 < 7 returns TRUE. |
> |
Greater than |
Returns whether x is greater than Y |
5 > 3 returns TRUE. If two operands are numbers, they are first converted to a common type. Otherwise, it always returns false. |
<= |
Less than or equal to |
Returns whether x is less than or equal to Y |
x = 3; y = 6; X <= y returns True. |
>= |
Greater than or equal to |
Returns whether x is greater than or equal to Y |
x = 4; y = 3; X >= y returns True. |
== |
Equals |
Compare objects for Equality |
x = 2; y = 2; x = = y returns True. x = ' str '; y = ' StR '; x = = y returns false. x = ' str '; y = ' str '; x = = y returns True. |
!= |
Not equal to |
Compare two objects for unequal |
x = 2; y = 3; X!= y returns True. |
Not |
Boolean "Non" |
Returns False if X is true. If x is False, it returns true. |
x = True; Not Y returns false. |
and |
Boolean "and" |
If x is False,x and Y returns false, it returns the calculated value of Y. |
x = False; y = True; X and Y, which returns false because X is false. Here, Python does not compute y because it knows that the value of the expression must be false (because X is false). This phenomenon is called short-circuit calculation. |
Or |
Boolean "or" |
If x is true, it returns true, otherwise it returns the calculated value of Y. |
x = True; y = False; X or Y returns true. Short-circuit calculations are also applicable here. |