+ The number type indicates addition , The string type represents the concatenation - The number type indicates subtraction * The number type represents multiplication , The string represents repeated output / Number type indicates Division // The numeric type represents an integer division ** Numeric types represent power functions ( namely n Power )% The numeric type represents remainder
Example
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" @file: The_Operator.py @author: Henry @datetime: 2022/6/25 0025 22:41 """
a = 9
b = 2
c = 'Hello '
d = 'Henry'
# String addition
print(c+d)
# String multiplication
print(c*2)
# division
print(a/b)
# to be divisible by
print(a//b)
# power function
print(a**b)
# Remainder
print(a%b)
Assignment operator
Operator
explain
= Assign the value on the right side of the operator to the variable on the left += The variable on the left side of the operator matches the expression on the right side of the operator Add , Then assign the result to the variable to the left of the operator -= The variable on the left side of the operator matches the expression on the right side of the operator reduce , Then assign the result to the variable to the left of the operator *= The variable on the left side of the operator matches the expression on the right side of the operator ride , Then assign the result to the variable to the left of the operator /= The variable on the left side of the operator matches the expression on the right side of the operator except , Then assign the result to the variable to the left of the operator //= Variable to the left of operator to be divisible by The expression to the right of the operator , Then assign the result to the variable to the left of the operator **= The variable on the left side of the operator is used for the expression on the right side of the operator The next power Then assign the result to the variable on the left of the operator again %= The variable on the left of the operator and the expression on the right of the operator Remainder Then assign the result to the variable on the left of the operator again
a = 9
b = 2
a /= b
print(a, b)
a = 9
b = 2
a //= b
print(a, b)
a = 9
b = 2
a **= b
print(a, b)
a = 9
b = 2
a %= b
print(a, b)
Relational operator
Operator
explain
> Greater than < Less than >= Greater than or equal to <= Less than or equal to == equal != It's not equal
Logical operators
Operator
explain
and Yes FALSE be FALSE, On both sides TRUE Then return to TRUEor Yes TRUE be TRUE, On both sides FALSE Then return to FALSEnot Take the opposite