Sujet : Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)
De : janburse (at) *nospam* fastmail.fm (Mild Shock)
Groupes : comp.lang.pythonDate : 08. Nov 2024, 21:49:55
Autres entêtes
Message-ID : <vglq12$bqo4$1@solani.org>
References : 1 2 3 4 5 6 7
User-Agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0 SeaMonkey/2.53.19
Ok here you go, the "walrus operator" is
actually a good lead, we have that this
here from JavaScript:
x++
respectively
++x
Can be replaced by the Python expression:
(x := x + 1) - 1
respectively
(x := x + 1)
Here is a test only testing x++:
Python 3.14.0a1 (tags/v3.14.0a1:8cdaca8, Oct 15 2024, 20:08:21)
>>> x = 5
>>> (x := x + 1) - 1
5
>>> x
6
dn schrieb:
... irrational drivel removed ..> The 'walrus operator' could be applied:
>>> x = 5
>>> y = (x := x + 1); x
6
>>> x, y
(6, 6)... irrational drivel removed ..