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?
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
not 0 == True (1) *Always!not 0 + 1 I guess that will answer your question
all- your question should be, why isnot(0) + 1false? You claim thata = [2]but if it were then you wouldn't have had to writenot(0) + 1to produce the issue.notis an operator, not a function, and has lower precedence than+, so you are effectively doingnot ((0) + 1).