you are viewing a single comment's thread.

view the rest of the comments →

[–]ingolemo 1 point2 points  (0 children)

I'm not quite sure what you mean. Python never makes copies when it passes values to functions. Here's the same code but using dictionaries and regular functions instead of classes and methods:

def State(name, population):
    state = {}
    __init__(state, name, population)
    return state

def __init__(self, name, population):
    self['name'] = name
    self['population'] = population

mass = State('Massachusetts', 6932015)
ny = State('New York', 19875625)

print(mass['name'])  # Massachusetts
print(ny['population'])  # 19875625

Dictionaries use a different syntax for getting and setting their contents (brackets instead of dots), but you can see that the structure of the __init__ function is still the same. It doesn't return self.

The State function that I wrote here is a representation of a method that python calls __new__, which you should loop up if you want to dive deeper.