Computer can be carried out many kinds of operations, can not only subtraction so simple, the operation by category can be divided into arithmetic operations, comparison operations, logical operations, assignment operations, member operations, identity operations, bit operations, today we temporarily only learn arithmetic operations, comparison operations, logical operations, assignment operations.
Arithmetic operations: Suppose a=20 b=10
Operator |
Operator description |
Instance |
+ |
Two objects added |
A + b outputs a result of 30 |
- |
Subtraction of two objects |
A-B outputs 10 |
* |
Multiply two objects |
A * b outputs a result of 200 |
/ |
Divide two objects |
A/b Outputs a result of 2.0 |
% |
Modulo returns the remainder after dividing |
A% b outputs a result of 0 |
** |
Power |
A * * b output 20 of 10 power |
// |
Division of integers returns the integer part after dividing
|
Example: 9//2 result is 4 |
Comparison operation: Suppose A=20 b=10
Operator |
Operator description |
Instance |
== |
Equals comparison of two objects equal |
A = = B result is false |
!= |
does not equal the comparison of two objects |
A! = B results are true |
<> |
does not equal the comparison of two objects |
A <> b results are true |
> |
Greater than compare which object has a larger value |
A > B results are true |
< |
Less than compare which object has a smaller value |
A < b result is false |
>= |
Greater than or equal |
A >= b result is true |
<= |
Less than or equal |
A <= b result is false |
Assignment operation:
Operator |
Operator description |
Instance |
= |
Simple assignment
|
A = 10 assigns a value of 10 to the A variable |
+= |
Addition assignment Operation #自加运算
|
A + = 10 equates to a=a+10 |
-= |
Subtraction Assignment Operation #自减运算 |
A-= 10 equates to a=a-10 |
*= |
Multiplication Assignment Operation #自乘运算 |
A *= 10 equates to a=a*10 |
/= |
Division assignment Operation #自除运算 |
A/= 10 equates to A=A/10 |
%= |
Modulo assignment operation |
A%= 10 equates to a=a%10 |
**= |
Power Assignment operation |
A **= 10 equates to a=a**10 |
//= |
Rounding Assignment operation |
A//= 10 equates to A=A//10 |
Logical operation: Suppose A=20 b=10
Operator
|
Operator description |
Instance |
and
|
"with" condition 1 and Condition 2 are satisfied for true |
A>10 and b<20 results are true |
Or |
"or" condition 1 or Condition 2 satisfies one is true |
a>15 or b>15 result is true |
Not |
Non- |
Not a>15 result is false |
Python Basics-Operators