3 ms·
I see a few alternatives for the first example here already, but none that take advantage of the walrus operator: # Assuming credit can't be negative.
by FreakLegion 3y ago
I see a few alternatives for the first example here already, but none that take advantage of the walrus operator:
# Assuming credit can't be negative.
if user and (balance := user.get_balance()) and (credit := balance.credit_amount()):
discount_program = choose_discount(credit)