0 votes
1 view
in Python by (47.7k points)

How would you say does not equal?

Like

if hi == hi:

print "hi"

elif hi (does not equal) bye:

print "no hi"

Is there something equivalent to == that means "not equal"?

1 Answer

0 votes
by (107k points)
edited by
 
Best answer

Yes, there a “not equal” operator in Python which is denoted by !=, if you want to compare object identity, you can use the keyword is and its negation is not.

Below is your code with the != operator:-

answer = 'hi'

if answer == 'hi':

  print("hi")

elif answer != 'hi':

  print("no hi")

image

To know more about this you can have a look at the following video tutorial:-

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...