0

In Python,

a=[not(0)+1] 
print(all(a))

This returns False. But shouldn't it be True? Since, a=[2], and all integer values other than 0 are considered True. Thus, all() should return True right?

4
  • This has nothing to do with all - your question should be, why is not(0) + 1 false? You claim that a = [2] but if it were then you wouldn't have had to write not(0) + 1 to produce the issue. Commented Jan 30, 2021 at 12:01
  • Fair enough. How is not(0)+1 =False? Shouldn't it be True? Commented Jan 30, 2021 at 15:19
  • The brackets are misleading; not is an operator, not a function, and has lower precedence than +, so you are effectively doing not ((0) + 1). Commented Jan 30, 2021 at 15:26
  • Ah. Now I understand! Thanks a lot! Commented Jan 30, 2021 at 16:20

1 Answer 1

1

Yes, all() should return True if all the values in a list are true. In your case if you do

a = [2]
print(all(a))

this will return true. But when you are doing

a = [not(0) +1]

your list of a is becoming a = [False] as not(0) + 1 returns False.

a = [2]
a = [not(0) + 1]
print(a)
# a = [False]
print(all(a))
# False

Hence, this prints result as False

Sign up to request clarification or add additional context in comments.

3 Comments

not 0 == True (1) *Always!
Allright. But I still do not understand how not(0)+1 returns False. I always thought not(0)=1, so (1+1)=2=True. What's wrong in this logic?
think of it as not 0 + 1 I guess that will answer your question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.