Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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

Why?

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]) 

image

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

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

image

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.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...