Others already gave you replies that cover your particular case. In general, however, when you actually need an if
-statement, you can use the conditional expression. For example, if you'd have to return strings "False"
and "True"
rather than boolean values, you could do this:
lambda num: "False" if num%2==0 else "True"
The definition of this expression in Python language reference is as follows:
The expression x if C else y
first evaluates C
(not x
); if C
is true, x
is evaluated and its value is returned; otherwise, y
is evaluated and its value is returned.