What is an operator?
This section mainly describes the Python operators. For a simple example 4 +5 = 9 . In the example, 4 and 5 are called operands, and "+" are called operators.
The Python language supports the following types of operators:
- Arithmetic Operators
- Comparing (relational) operators
- Assignment Operator
- Logical Operators
- Bit Operator
- Member Operators
- Identity Operator
- Operator Priorities
Next let's learn Python operators one by one.
Python Arithmetic Operator
The following hypothetical variables: a=10, b=20:
|+||Plus - Add two objects||a + b Output 30|
|-||minus - get a negative number or a number minus another number||a - b output result -10|
|*||multiply - multiply two numbers or return a string that is repeated several times||a * b output result 200|
|/||Division - x divided by y||b / a Output 2|
|%||modulo - returns the remainder of the division||b % a output 0|
|**||power - returns the power of y of x||a**b is the 20th power of 10, and the output is 100000000000000000000|
|//||Division - Returns the integer part of the quotient (round down)||
>>> 9//2 4 >>> -9//2 -5
The following example demonstrates the operation of all Python arithmetic operators: