[docs] misbehaving functionality of all() function

Julien Palard julien at palard.fr
Tue May 21 09:36:59 EDT 2019


Hi Sai,

> I was going through python 3.6 docs and i am finding all function is behaving differently when working with variables and lists.
>
> The all() function is not iterable for complex numbers. but when I am passing complex number in list, the all function returns True.
> l = [1,2,1+12.1j]
>
> all(l)

I'm not sure to understand your question.

all() tells you if all elements of the given iterable are truthy.

So in your case all([1, 2, 1+12.1j]) returns True because at least one (in fact all) elements are truthy.

In Python, empty things, None, False, and zeroes are False, everything else is True, so 1 is truthy, 2 is truthy, also 1+12.1j. see:

>>> bool(1), bool(2), bool(1+12.1j)
(True, True, True)

When you say "behaving differently when working with variables and lists", as long as you're speaking with variable pointing to lists, it should be false, so:

x = [type anything here]
all(x) == [type the same thing here]

is always true, all does not sees the difference when passed a variable or the actual list (it sees a list object in both cases).

Bests,
-- 
Julien Palard
https://mdk.fr



More information about the docs mailing list