Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

What is the difference between these two lines of code:

if not x == 'val':

and

if x != 'val':

Is one more efficient than the other?

Would it be better to use

if x == 'val': 

   pass else:

1 Answer

0 votes
by (106k points)

It depends on how you read it:-

if not x == 'val':

But != could be read in a better context as an operator which does the opposite of what == does.

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

Related questions

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

Browse Categories

...