Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k 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"?

closed

1 Answer

0 votes
by (106k 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:-

Related questions

0 votes
1 answer
0 votes
1 answer
asked Sep 25, 2019 in Python by Sammy (47.6k points)
0 votes
2 answers

Browse Categories

...