How do I pass a variable by reference?
@lebyy▲ 0 net votes
Problem: I wrote this class for testing: class PassByReference: def __init__(self): self.variable = 'Original' self.change(self.variable) print(self.variable) de When I tried creating an instance, the output was Original . So it seems like parameters in Python are… Fix (from the top answer): Arguments are passed by assignment . The rationale behind this is twofold: the parameter passed in is actually a reference to an object (but the reference is passed by value) some data types are mutable, but others aren't So: If you pass a mutable object into a method, the method gets a reference to that same object…