[Tutor] all( ) built in function
Alan Gauld
alan.gauld at yahoo.co.uk
Wed Oct 14 19:08:07 EDT 2020
On 14/10/2020 18:26, Manprit Singh wrote:
> Dear Sir ,
>
> I just want to check my understanding of using all( ), a built in
> function, with examples given below :
As others have said the best way to check your understanding in
Python is to ask the interpreter. It will give you a definitive
answer. And it is much faster than typing an email and then
waiting for a response. It's why it exists.
> test_seq = [ [2, 3], [3, 6], [ ], [4, 8] ]
> all(test_seq) will return False as test_seq contains an empty list which is
> considered as false object when tested for truth value
>
> t_lst = [3, 5, 6, 0, 7]
> all(t_lst) will also return False as t_lst contains a 0 which is
> considered as a false object when tested for truth value.
>
> test_s = [None, True, True, True]
> all(test_s) will also return False as test_s contains None which is
> considered as a false object when tested for truth value.
>
> t_s = [3, 5, 8, 9]
> all(t_s) will return True as every element of t_s is considered as a true
> object when tested for truth value.
You're understanding is correct in all cases.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list