Jun-22-2023, 06:18 AM
(This post was last modified: Jun-22-2023, 06:21 AM by Gribouillis.)
(Jun-21-2023, 08:20 PM)Clunk_Head Wrote: did my first code create one lambda that was referenced by all buttons, or did it crate a lambda for each function that all referenced the same variables?It created a lambda for each button that all referenced to the same variables as in this example
>>> def func(): ... var = 3 ... spam = lambda: var ... var = 4 ... ham = lambda: var ... return spam, ham ... >>> f, g = func() >>> f is g False >>> f.__closure__ (<cell at 0x7f3135163160: int object at 0x7f3135374150>,) >>> g.__closure__ (<cell at 0x7f3135163160: int object at 0x7f3135374150>,) >>> f.__closure__[0].cell_contents 4 >>> g.__closure__[0].cell_contents 4 >>>