mardi 21 septembre 2021

Multiple if/else on list comprehensions

I am trying to learn list comprehensions Conditionals on inerrable. My problem is, I don't understand how my if/else condition working on this list. which if or else working first and printing.

num1 = [5,10,15]
num2 = [i**2 if i == 10 else i-5 if i < 7 else i+5 for i in num1]
print(num2)

Output:
[0,100,20]

Aucun commentaire:

Enregistrer un commentaire