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

Life of Brian: Conjugate the verb, "to go" !

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  'int' object does not support item assignment shane1236 5 195 Aug-13-2019, 01:53 PM
Last Post: buran
  Question Regarding the == Operator majorjohnusa 4 107 Aug-12-2019, 06:53 PM
Last Post: ichabod801
  Assignment operator DavidTheGrockle 7 193 Aug-11-2019, 07:16 AM
Last Post: ThomasL
  Simple Matrix Assignment m_llaa 10 425 Aug-05-2019, 09:35 AM
Last Post: m_llaa
  The following script works but I need to take it one step further to milliseconds. yeto 1 157 Jul-19-2019, 04:15 AM
Last Post: micseydel
  Error: int object does not support item assignment ankita_nthu 2 176 Jul-07-2019, 02:14 PM
Last Post: ankita_nthu
  Simple while loop only works on first attempt jsb83 2 172 Jun-20-2019, 08:57 PM
Last Post: jsb83
  Reproducing assignment with min cost flow in networkx mntfr 0 142 Jun-13-2019, 04:06 PM
Last Post: mntfr
  Code works in IDLE, appears to work in CMD, but won't produce files in CMD/Windows ChrisPy33 3 407 Jun-12-2019, 05:56 AM
Last Post: ChrisPy33
  AND Boolean operator syntax error jsb83 3 331 May-31-2019, 08:34 AM
Last Post: perfringo

Forum Jump:

Users browsing this thread: 1 Guest(s)