3 ms·
Especially given the first example is tailor-made for the walrus operator. if (balance := user.get_balance()) and (credit := balance.credit_amount()):
by FreakLegion 5y ago
Especially given the first example is tailor-made for the walrus operator.
if (balance := user.get_balance()) and (credit := balance.credit_amount()):
discount_program = choose_discount(credit)
(Omitting the credit > 0, and without getting into other fundamental issues with the implied design, since it's just a readme example.)