0

I'm new in Python and I have a question. Is this possible to assign if-else statement into a variable in the same line? Thanks.

Aram
  • 11
  • 1

2 Answers2

0

You can try Python's conditional expression :

a = 1
even = 'true' if a%2==0 else 'false'

You'll find the official documentation for conditional expression here.

-1

In python,lambda function.
this is example how you can use it.

max = lambda a, b : a if(a > b) else b
 
print(max(1, 2))
print(max(10, 2))

#output:
#2
#10
QuantumX
  • 118
  • 9