C Lang/machine learing

4-6, 4-7. series operation, lambda

iliosncelini 2019. 2. 24. 15:55







*lambda 내의 if문


a = 2
result = 'negative' if a < 0 else 'positive' if a > 0 else 'zero'
print(result)
# positive

a = -2
result = 'negative' if a < 0 else 'positive' if a > 0 else 'zero'
print(result)
# negative

a = 0
result = 'negative' if a < 0 else 'positive' if a > 0 else 'zero'
print(result)
# zero


https://note.nkmk.me/python-if-conditional-expressions/