Home > Article > Backend Development > What is the difference between = and == in python?
In Python, "=" means assignment; "==" is used to determine whether they are equal; if they are equal, then "true" will be returned; if they are not equal, then "false" will be returned.
"=" in python means assignment; "==" is used to determine whether they are equal
The difference between them is that they represent different meanings.
The meaning of an equal sign is assignment, assigning a certain value to a variable, such as a=3, assigning the value 3 to a.
Two equal signs are used to determine whether they are equal and return True or False, such as 1==1. If they are equal, then return true. 1==2, they are not equal, then return false.
Extended information
Python’s expression writing method is similar to C/C. There are only differences in some writing methods. The main arithmetic operators are similar to C/C.
, -, *, /, //, **, ~, % respectively represent addition or positive, subtraction or negative, multiplication, division, integer division, exponentiation, complement and remainder. >>,
&, |, ^ represents binary AND, OR, XOR operations.
>, = are used to compare the values of two expressions, indicating greater than, less than, equal to, not equal to, less than or equal to, and greater than equal.
Among these operators, ~, |, ^, &, > must be applied to integers.
Recommended tutorial: "python tutorial"
The above is the detailed content of What is the difference between = and == in python?. For more information, please follow other related articles on the PHP Chinese website!