Python – Ternary Operator


a = 5
if a < 10:
    print('a < 10')
else:
    print('a >= 10')
a < 10
a = 5
res = 'a < 10' if a < 10 else 'a >= 10'
print(res)
a < 10
a = 15
if a < 10:
    print('a < 10')
else:
    print('a >= 10')
a >= 10
a = 15
res = 'a < 10' if a < 10 else 'a >= 10'
print(res)
a >= 10

Fermer le menu