My path to Python development-first day --- Python BASICS (4) --- December 26, 2015 (smog ),
V. Data Operations and Data Operators
Arithmetic Operators
Arithmetic Operators
Operator |
Description |
Example |
+ |
Addition |
>>> 14-5 9 |
- |
Subtraction |
>>> 14 - 59 |
* |
Multiplication |
>>> 5 * 1470 |
/ |
Division |
>>> 14 / 52.8 |
% |
Modulo, that is, the remainder of two operators |
>>> 14 % 54 |
** |
Power Operation |
>>> 2 ** 38 |
// |
Returns the integer part of the quotient of two numbers. |
>>> 10 // 33 |
Comparison operators: Comparison operators are not limited to numbers, strings, lists, and so on.
Comparison Operators
Operator |
Description |
Example |
= |
Determine whether two objects are equal (True is returned if they are equal, False is returned if they are not equal) |
>>> 'abc' == 'abc'True |
! = |
Checks whether the connected objects are not equal (opposite to =). If they are equal, False is returned. If they are not equal, True is returned) |
>>> 1 != 2True |
<> |
Determine whether the connected objects are not equal (same as above, but not recommended) |
|
> |
Judge whether the first object is greater than the second object. If the value is greater than True, no greater than (including equal), return Fasle. |
>>> 3 > 1True |
< |
Judge whether the first object is smaller than the second object. If the value is smaller than or equal to True, return Fasle. |
>>> 3 < 4True |
> = |
Determines whether the first object is greater than or equal to the second object. If the value is greater than or equal to the second object, True is returned. Otherwise, False is returned. |
>>> 3 >= 3True |
<= |
Determines whether the first object is less than or equal to the second object. If the value is less than or equal to the second object, True is returned. Otherwise, False is returned. |
>>> 3 <= 4True |
Value assignment operator: Performs value assignment.
Value assignment operator
Operator |
Description |
Example |
= |
Assignment |
A = c |
+ = |
Auto-increment value a + = 1 is equivalent to a = a + 1 |
A + = 1 |
-= |
The auto-subtraction value a-= 1 is equivalent to a = a-1. |
A-= 1 |
* = |
The auto-multiplication value a * = 1 is equivalent to a = a * 1. |
A * = 1 |
/= |
The auto-division value a/= 1 is equivalent to a = a/1. |
A/= 1 |
% = |
The automodulo value a % = 1 is equivalent to a = a % 1. |
A % = 1 |
** = |
The self-calculated power value a ** = 1 is equivalent to a = a ** 1 |
A ** = 1 |
// = |
Auto-Division assignment a // = 1 is equivalent to a = a // 1 |
A // = 1 |
Bitwise OPERATOR: Performs logical computing based on binary
Bitwise operators
Operator |
Description |
Example |
& |
Bitwise AND |
>>> 5 & 144 |
| |
By bit or |
>>> 5 | 1415 |
^ |
Exclusive or |
>>> 5 ^ 1411 |
< |
Move left |
>>> 14 << 256 |
> |
Right Shift |
>>> 14 >> 23 |