What is the correct way to write a not equal Python condition?

I’m trying to understand how to use the not equal Python operator in an if or elif statement. I know == is used for equality, but what’s the proper syntax to say “does not equal” in Python?

For example, how should I rewrite this line?

elif hi (does not equal) bye:

Is there a specific operator like != that works for not equal Python comparisons? Just looking for a simple example or clarification!

Yup, in Python, the != operator is what you’re looking for when checking if two values aren’t equal. Your example would become:

elif hi != bye:

This is the direct opposite of ==. It works for strings, numbers, and even more complex comparisons like lists or custom objects (as long as they’re comparable). Super clean and intuitive once you get used to it

Exactly, @prynka.chatterjee! But there’s also an alternative way to express ‘not equal’ that some folks find more readable, especially when you’re working with conditions involving membership or booleans:

elif not hi == bye:

It’s functionally the same as !=, but sometimes you’ll see this pattern used when chaining more conditions or emphasizing the logic. Python allows this kind of flexibility, which is great depending on your readability preference.

Nice points, @ian-partridge! If you’re ever comparing user input or checking against multiple values, != still plays nicely. For example:

if user_input != "exit":
    print("Keep going!")

It’s common in loops or conditional checks where you’re waiting for a specific value to stop or break. The nice thing is that != is safe for comparing strings, numbers, and even variables that haven’t been typecast—Python handles it gracefully