Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 assignment: not an operator nor expression, but x=y=z=3 works fine?
When I read the Python reference (Assignment statements), the documenation doesn't describe an repeated assingment syntax (as far as my BNF knowledge brings me).

Still, if I code a=b=c=d=3, the variables a b c and d get the value 3

If they were interpreted from left to right (like C#) and the assignment were an expression (operator) with the assigned value as the result, it would be ok, but the same documentation doesn't mention this. Also, the assignment is not found among the operators (nor the operator precedence list)

Although it works and doesn't give me any problems, I'm curious about how this relates to the reference: am I overlooking something? (if I want to use the reference to work out about details, I should know how to interpret that reference, and this doesn't seem the case right now)

Kind regards, and thanks in advance,
Jef Daels
You can read detailed answer from StackOverflow: Python Multiple Assignment Statements In One Line

Somewhat loosely related (from documentation you referred):

Quote:Although the definition of assignment implies that overlaps between the left-hand side and the right-hand side are ‘simultaneous’ (for example a, b = b, a swaps two variables), overlaps within the collection of assigned-to variables occur left-to-right, sometimes resulting in confusion. For instance, the following program prints [0, 2]:

x = [0, 1]
i = 0
i, x[i] = 1, 2         # i is updated, then x[i] is updated
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.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Pyautogui script runs fine if split into two parts together it does not Bmart6969 1 126 Oct-07-2019, 10:53 PM
Last Post: Bmart6969
  Assignment operator DavidTheGrockle 7 309 Aug-11-2019, 07:16 AM
Last Post: ThomasL
  How many variables/values are limited to single assignment operator? Prabakaran141 1 510 Sep-06-2018, 03:32 PM
Last Post: Larz60+
  assignment embedded in an expression Skaperen 11 2,001 Nov-25-2017, 03:37 AM
Last Post: Skaperen
  Dict KeyError in cgi-bin script, works fine via console dbsoundman 2 1,200 Jul-21-2017, 08:03 PM
Last Post: dbsoundman

Forum Jump:

Users browsing this thread: 1 Guest(s)