Skip to content
Advertisement

Multiple “calculation AND assignment” operations in one line of python?

Let’s say I would like to divide by 2, add 1 and multiply by 5.

Something like

JavaScript

obviously doesn’t work.

I tried different combinations using parentheses and the walrus operator, but couldn’t produce produce something working, even less something well readable

Advertisement

Answer

This isn’t something you can chain. There’s nothing wrong with the perfectly readable

JavaScript

or

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement