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

If I do this:

>>> False in [False, True] True

That returns True. Simply because False is in the list.

But if I do:

>>> not(True) in [False, True] False

That returns False. Whereas not(True) is equal to False:

>>> not(True) False


1 Answer

0 votes
by (106k points)

You are not getting your desired output due to Operator precedence:-

The precedence of the operator not is lower than the operator in. So it is equivalent to:

>>> not ((True) in [False, True]) 


To get your desired output you need to write it like as follows:-

>>> (not True) in [False, True]


It should always remember not to write not(True), you should always prefer not True. Writing not(True) makes it look like a function call, while not is an operator, not a function.

Browse Categories