Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #196985

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

From Mild Shock <janburse@fastmail.fm>
Newsgroups comp.lang.python
Subject Re: Two aces up Python's sleeve (Posting On Python-List Prohibited)
Date 2024-11-08 20:49 +0100
Message-ID <vglq12$bqo4$1@solani.org> (permalink)
References (2 earlier) <050c2ce9efd8442fb902ecc926afb1ee42fe6c34.camel@tilde.green> <vgjoe9$2stii$2@dont-email.me> <vgjq77$aj8c$1@solani.org> <59a78893-d96a-4f5b-921f-5ad862449ca2@DancesWithMice.info> <mailman.88.1731092996.4695.python-list@python.org>

Show all headers | View raw


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 ..

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: Two aces up Python's sleeve Mild Shock <janburse@fastmail.fm> - 2024-11-06 17:27 +0100
  Re: Two aces up Python's sleeve Annada Behera <annada@tilde.green> - 2024-11-07 12:55 +0530
    Re: Two aces up Python's sleeve Mild Shock <janburse@fastmail.fm> - 2024-11-07 15:04 +0100
      Re: Two aces up Python's sleeve Greg Ewing <greg.ewing@canterbury.ac.nz> - 2024-11-08 11:15 +1300
        Re: Two aces up Python's sleeve dn <PythonList@DancesWithMice.info> - 2024-11-08 13:07 +1300
        Re: Two aces up Python's sleeve Mild Shock <janburse@fastmail.fm> - 2024-11-08 01:25 +0100
          Re: Two aces up Python's sleeve Mild Shock <janburse@fastmail.fm> - 2024-11-08 01:29 +0100
            Re: Two aces up Python's sleeve Mild Shock <janburse@fastmail.fm> - 2024-11-08 01:47 +0100
    Re: Two aces up Python's sleeve (Posting On Python-List Prohibited) Lawrence D'Oliveiro <ldo@nz.invalid> - 2024-11-08 01:10 +0000
      Re: Two aces up Python's sleeve (Posting On Python-List Prohibited) Mild Shock <janburse@fastmail.fm> - 2024-11-08 02:40 +0100
        Re: Two aces up Python's sleeve (Posting On Python-List Prohibited) dn <PythonList@DancesWithMice.info> - 2024-11-09 08:09 +1300
          Re: Two aces up Python's sleeve (Posting On Python-List Prohibited) Mild Shock <janburse@fastmail.fm> - 2024-11-08 20:49 +0100
        Re: Two aces up Python's sleeve (Posting On Python-List Prohibited) Thomas Passin <list1@tompassin.net> - 2024-11-08 17:00 -0500

csiph-web