Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python 3.8 :=
#3
(Dec-22-2019, 02:02 AM)ichabod801 Wrote: So it looks like y := x would fail by itself.

Yep, it is so:

>>> x := 5
  File "<stdin>", line 1
    x := 5
      ^
SyntaxError: invalid syntax
>>> (x := 5)
5
I prefer to use assignment expressionn in cases where it actually shortens the code, avoids calculation of same value and makes it more concise.

Example of calculating once (minimum number of page flips to location starting either from beginning or end):

min(from_start := location // 2, total_pages // 2 - from_start)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Python 3.8 := - by jgitlin - Dec-22-2019, 01:16 AM
RE: Python 3.8 := - by ichabod801 - Dec-22-2019, 02:02 AM
RE: Python 3.8 := - by perfringo - Dec-22-2019, 07:52 AM
RE: Python 3.8 := - by jgitlin - Dec-22-2019, 01:51 PM
RE: Python 3.8 := - by ichabod801 - Dec-22-2019, 03:03 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020