• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Not Equal Operator != in Python

Not Equal Operator != in Python

September 12, 2022 Leave a Comment

You can check if an object is not equal to another object in Python with the not equal operator !=.

a = 0
b = 1

if a != b:
    print("a is not equal to b")

#Output:
a is not equal to b

When working with objects and variables in Python, the ability to check if two variables have the same value or a different value easily is valuable.

One such case is if you want to check if a variable is not equal to another variable in Python.

You can check if an object is not equal to another object in Python with the not equal operator !=.

!= is a Python comparison operator and allows you to compare the values of objects.

Below is a simple example showing you how to check if two variables are not equal to each other in Python.

a = 0
b = 1

if a != b:
    print("a is not equal to b")

#Output:
a is not equal to b

Checking if an Object is Equal to Another in Python with !=

The != operator works to check if the value of the objects is the same but doesn’t work to check if the identities and memory locations are the same like the is keyword.

Below shows an example of how != is different from is and not is in Python.

a = [0]
b = [0]

print(a == b)
print(a != b)
print(a is b) 
print(a is not b)

#Output:
True
False
False
True

Hopefully this article has been useful for you to learn about the not equal operator != in Python.

Other Articles You'll Also Like:

  • 1.  pandas idxmax – Find Index of Maximum Value of Series or DataFrame
  • 2.  Using Python to Sum the Digits of a Number
  • 3.  Using Python to Check If List of Words in String
  • 4.  What Curly Brackets Used for in Python
  • 5.  pandas nsmallest – Find Smallest Values in Series or Dataframe
  • 6.  Cartesian Product of Two Lists in Python
  • 7.  Selenium minimize_window() Function to Minimize Window in Python
  • 8.  Flatten List of Tuples in Python
  • 9.  Python turtle Colors – How to Color and Fill Shapes with turtle Module
  • 10.  Read First Line of File Using Python

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy