samedi 22 août 2020

What does an if statement evaluate a list to?

What does an if statement on a list in python evaluate to? I remember reading somewhere that if you do it on an empty list if evaluates to false and otherwise it evaluates to True. Is there any reason to check for the list length also?

For example:

list = [10]*10

if list:
    print("First check)

if list and len(list):
    print("Second check")

What do the above two checks look at? They both evaluate to true.

Aucun commentaire:

Enregistrer un commentaire