Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)

Liste des GroupesRevenir à cl python 
Sujet : Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)
De : list1 (at) *nospam* tompassin.net (Thomas Passin)
Groupes : comp.lang.python
Date : 08. Nov 2024, 23:00:31
Autres entêtes
Message-ID : <mailman.89.1731115813.4695.python-list@python.org>
References : 1 2 3 4 5 6 7
User-Agent : Mozilla Thunderbird
On 11/8/2024 2:09 PM, dn via Python-list wrote:
On 8/11/24 14:40, Mild Shock via Python-list wrote:
Well you can use your Browser, since
JavaScript understand post and pre increment:
 Question: are we talking Python or JavaScript?
 
So we have x ++ equals in Python:
 Trying to find a word-for-word translation serves as badly in computer- programming languages as it does in human spoken-languages. Learn how to adapt and embrace the differences...
 
     x + = 1
     x - 1
 The above probably only 'works' (the way you expect) in the REPL.
 
But I don't know how to combine an
assignment and an expression into one
expession. In JavaScript one can use
 Again!
 "Everything should be made as simple as possible, but no simpler."
 Check out "The Zen of Python" and PEP-0008 for Python idioms.
 
the comma:
>
 > x = 5
5
 > y = (x += 1, x - 1)
5
 > x = 5
5
 > y = (x += 1, x)
6
>
But in Python the comma would create a tuple.
 Exactly, just as driving on the left side of the road will be fine in some countries but cause a crash in others. Learn the local rules FIRST!
  The 'walrus operator' could be applied:
  >>> x = 5
 >>> y = (x := x + 1); x
6
 >>> x, y
(6, 6)
 However, if such were submitted for Code Review, unhappiness would result.
  Was the question re-phrased to: how to ... in Python, we'd end-up with something more like this:
  >>> x = 5  # define
 >>> x += 1  # increment
 >>> y = x  # alias
 >>> x, y
(6, 6)
Or, still Pythonic but simpler:
 >>> x = 5
 >>> y = x = x + 1
 >>> x, y
(6, 6)

Date Sujet#  Auteur
6 Nov 24 * Two aces up Python's sleeve15Stefan Ram
6 Nov 24 `* Re: Two aces up Python's sleeve14Mild Shock
7 Nov 24  `* Re: Two aces up Python's sleeve13Annada Behera
7 Nov 24   +- Re: Two aces up Python's sleeve1Stefan Ram
7 Nov 24   +* Re: Two aces up Python's sleeve6Mild Shock
8 Nov 24   i`* Re: Two aces up Python's sleeve5Greg Ewing
8 Nov 24   i +- Re: Two aces up Python's sleeve1dn
8 Nov 24   i `* Re: Two aces up Python's sleeve3Mild Shock
8 Nov 24   i  `* Re: Two aces up Python's sleeve2Mild Shock
8 Nov 24   i   `- Re: Two aces up Python's sleeve1Mild Shock
8 Nov 24   `* Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)5Lawrence D'Oliveiro
8 Nov 24    `* Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)4Mild Shock
8 Nov 24     +* Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)2dn
8 Nov 24     i`- Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)1Mild Shock
9 Nov 24     `- Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)1Thomas Passin

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal