In Python, the assignment operator refers to the equal sign =. In programming language, the meaning of the equal sign is no longer the mathematical equivalent of 1+1=2. What it really means is that the result to the right of = is assigned to the variable to the left.

For example, if you define a variable num=1, calculate the value on the right-hand side of the equal sign and assign the value to the variable on the left-hand side of the equal sign. In this case, the num variable is the reference address of 1 in memory. In the future, when we want to use the data 1, we can directly take out the num variable and read the data corresponding to the num variable, which is 1.

Definition of assignment operator

The operator describe The instance
= The assignment Assign the result to the right of = to the variable to the left of the equal sign

Two, assignment operator writing:

2.1 Assignment of a single variable

num= 1

print(num)

Copy the code

2.2 Multiple variable assignments

Note: Multiple variable assignments, the number of variables on the left side of the equal sign should be the same as the number of data on the right side of the equal sign, separated by English commas between each data, and the sequence of variables and data should correspond one by one.

Multiple variable assignment parsing: assigns 3 to num1, 0.8 to float1, and str1 to the Python self-learning network

num1,float1,str1 = 3.0.8.'Python Self-study Network '
print(num1)

print(float1)
print(str1)

Copy the code

The result is as follows:

2.3 Assigning the Same Value to multiple Variables

Assignment process: Assign 100 to variable A and also to variable B

a = b = 100
print(a)
print(b)
Copy the code

The result is as follows:


There are five classes of arithmetic operators in Python, and this is just one of them. Therefore, beginners should be patient and careful to learn and practice in the future.