jeudi 11 novembre 2021

python lists with for loop and if-else statement [duplicate]

I want to use the one lined syntax for the "for_loop/if/elif/else/lists" for the code under:

for i in range(20):
    if(i<15):
        print("True")
    else:
        print("False")

this is a part of it

[True for i in range(20) if i<15]

How to add the "else" for it?

Aucun commentaire:

Enregistrer un commentaire