learning target:
算术运算符
比较(关系)运算符
逻辑运算符
赋值运算符
运算符的优先级
Learning Content:
A) Arithmetic Operators
- Is a complete basic arithmetic symbols used for mathematical processing
Operators | description | Examples |
---|---|---|
+ | plus | 10 + 20 = 30 |
- | Less | 10 - 20 = -10 |
* | Multiply | 10 * 20 = 200 |
/ | except | 10 / 20 = 0.5 |
// | Take divisible | (Supplier) 2 9 // output portion 4 to return the integer division |
% | Take the remainder | Returns the division remainder = 1 2 9% |
** | power | Also known as power, power, 2 3 = 8 ** |
- Results in Python string operators may also be used, the calculation results of the specified number of times the string is
B) Comparison (relationship) operator
Operators | description |
---|---|
== | Check the value of the two operands if equal , if so, the condition is true, returns True |
!= | Check the value of the two operands if not equal , if so, the condition is true, returns True |
> | Check whether the value of the left operand is greater than the value of the right operand, if so, the condition is true, returns True |
< | Check the value of the left operand if less than the value of the right operand, if so, the condition is true, returns True |
>= | Check whether the value of the left operand is greater than or equal to the value of the right operand, if so, the condition is true, returns True |
<= | Check the value of the left operand if less than or equal to the value of the right operand, if so, the condition is true, returns True |
Python 2.x is judged not equal can also be used
<>
operators
!=
in Python 2.x likewise be used to determine not equal
C) logical operators
Operators | Logical expression | description |
---|---|---|
and | x and y | Only the values of x and y are True, will return True or as long as x or y has a value of False, it returns False |
or | x or y | As long as x or y has a value of True, it returns True only values of x and y are both False, will return False |
not | not x | If x is True, it returns False if x is False, returns True |
Iv) assignment operator
- In python, you can assign values to variables using the =
- When the arithmetic operation, to simplify the code written, Python also provides a series of arithmetic operators corresponding to the assignment operator
- Note: the assignment operator can not use the intermediate spaces
Operators | description | Examples |
---|---|---|
= | Simple assignment operator | c = a + b a + b is the assignment of the operation result c |
+= | Addition assignment operator | c + = a is equivalent to c = c + a |
-= | Subtraction assignment operator | c - = a is equivalent to c = c - a |
*= | Multiplication assignment operator | equivalent to c * = a c = c * a |
/= | Division assignment operator | c / = a is equivalent to c = c / a |
//= | Assignment operator take divisible | c // = a is equivalent to c = c // a |
%= | Take modulus (remainder) assignment operator | c% = a is equivalent to c = c% a |
**= | Power assignment operator | c ** = a is equivalent to c = c ** a |
E) operator precedence
- Arithmetic the priority table is arranged from high to low order
Operators | description |
---|---|
** | Power (highest priority) |
* / % // | Multiply, divide, take the remainder, taking divisible |
+ - | Addition, subtraction |
<= < > >= | Comparison Operators |
== != | Equality operator |
= %= /= //= -= += *= **= | Assignment Operators |
not or and | Logical Operators |
Attention
: Not supported in python increment and decrement (a ++, a -, ++ a, -a)