Home > Backend Development > Python Tutorial > What is used to express not equal in python?

What is used to express not equal in python?

爱喝马黛茶的安东尼
Release: 2019-11-23 15:00:08
Original
28845 people have browsed it

It does not mean what to use to express it in python. It is very simple and widely used.

What is used to express not equal in python?

Recommended manual: Python basic introductory tutorial

In the Python language, use! = means not equal. We understand it through the following simple example:

>>> x=3
>>> y=4
>>> if x !=y:
print(x+y)
else:
print(x-y)
7
Copy after login

In the above example, variables x and y are assigned values ​​first, and then the if statement is used to determine whether x and y are equal. If they are not equal, x y is printed. value; if equal, print the value of x - y. Obviously, x is not equal to y, and the result is the value of x y, which is 7. In the above example, != is the inequality symbol, which is formed by! Used in combination with =.

>>> 10 !=10
False
>>> 10 != 11
True
>>> a=[1,2]
>>> b=[2,3]
>>> a !=b
True
Copy after login

We use Python to verify that 10 is not equal to 10. The returned result is that 10 is not equal to 11. The result returns True to verify whether the a list and the b list are equal. The same return is False because they themselves are not equal. !
So far, we have mastered how to express inequality in Python, which is expressed by !=. Not only can it determine whether two numbers and lists are equal, it can also verify whether two strings, tuples, dictionaries, or sets are equal!

Recommended related articles:
1.Seven basic Python operators
2.python operator - the most commonly used comparison operator in programming (example analysis)
Related video recommendations:
1.Zero Basic Introduction to Little Turtle Learn Python video tutorial

The above is the detailed content of What is used to express not equal in python?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template