Can someone help me understand why the following Python script returns True?
True
x = '' y = all(i == ' ' for i in x) print(y)
I assume this is due to the fact that it xis an object with zero length, but cannot fully understand.
x
all()always returns Trueif there is no element in the sequence False.
all()
False
0 elements are created in your loop, therefore it is returned True.
This is documented :
True, ( ).
.
, any() False, True, , any() :
any()
>>> any(True for _ in '') False
, all:
all