How to assign a variable in an IF condition, and then return it?

Starting Python 3.8, and the introduction of assignment expressions (PEP 572) (:= operator), it’s now possible to capture the condition value (isBig(y)) as a variable (x) in order to re-use it within the body of the condition:

if x := isBig(y): return x

Leave a Comment