Python Forum
assignment embedded in an expression
Thread Rating:
  • 3 Vote(s) - 2.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
assignment embedded in an expression
#10
(Nov-24-2017, 01:50 AM)Skaperen Wrote: but i was afraid of doing a = b = c = {} out of fear that a, b, and c would all be referencing the same dictionary
It would dot that:
>>> a = b = c = {}
>>> id(a)
8350192
>>> id(b)
8350192
>>> id(c)
8350192
Easy fix:
>>> a, b, c = [{} for i in range(3)]
>>> id(a)
8358720
>>> id(b)
52826352
>>> id(c)
8358672

>>> help(id)
Help on built-in function id in module builtins:

id(obj, /)
    Return the identity of an object.    
    This is guaranteed to be unique among simultaneously existing objects.
    (CPython uses the object's memory address.)
Reply


Messages In This Thread
assignment embedded in an expression - by Skaperen - Nov-22-2017, 08:37 AM
RE: assignment embedded in an expression - by snippsat - Nov-24-2017, 02:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pass results of expression to another expression cmdr_eggplant 2 2,382 Mar-26-2020, 06:59 AM
Last Post: ndc85430
  assignment: not an operator nor expression, but x=y=z=3 works fine? jefdaels 1 2,268 Jan-29-2019, 02:19 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

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