Home  >  Article  >  Backend Development  >  How to express not equal in python

How to express not equal in python

silencement
silencementOriginal
2019-06-20 13:50:0958985browse

How to express not equal in python?

How to express not equal in python

Recommended manual: Python basic introductory tutorial

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

How to express not equal in python

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, print the value of x y; if they are 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 17. In the above example, != is the inequality symbol, which is formed by! Used in combination with =.

Another example, as follows

How to express not equal in python

We use Python to verify that 40 is not equal to 40, and the returned result is False, which is wrong ;Verify that 45 is not equal to 48, and the result returns True. Verify that list a and list b are equal. False is also returned because they are not equal!

So far, we have mastered how to express inequality in Python, which is represented 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 How to express not equal 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