Home  >  Article  >  Backend Development  >  What is the difference between = and == in python?

What is the difference between = and == in python?

烟雨青岚
烟雨青岚Original
2020-07-16 13:58:5932904browse

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.

What is the difference between = and == in python?

"=" 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.

What is the difference between = and == in python?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn