How does "everything" work in Python?

I was looking for an understanding of the all function in Python, and I found this , as per here:

all will return True only when all elements are Truthy.

But when I work with this function, it acts differently:

 '?' == True # False '!' == True # False all(['?','!']) # True 

Why do all elements in the input False return True ? Did I understand its functionality or is there an explanation?

+5
source share
3 answers

only if all elements are truthy.

Truthy! = True .

all essentially checks if bool(something) True (for all something in an iterable).

 >>> "?" == True False >>> "?" == False # it not False either False >>> bool("?") True 
+9
source

'?' and '!' are true because they are non-empty strings.

There is a difference between True and "truth." Truthy means that under duress, it can be evaluated to True . This is different from what it == to True .

+1
source

The all () function is used when we want to check if all the elements in the list are iterable or not. For example: x=[1,2,3,4,5] all(x) It will return True.

-1
source

Source: https://habr.com/ru/post/1244058/


All Articles