Python optional parameters

Viewed 31668

Guys, I just started python recently and get confused with the optional parameters, say I have the program like this:

class B:
   pass

class A:
    def __init__(self, builds = B()):
        self.builds = builds

If I create A twice

b = A()
c = A()

and print their builds

print b.builds
print c.builds

I found they are using the exactly same object,

<__main__.B instance at 0x68ee0>
<__main__.B instance at 0x68ee0>

But it is not what I want, since if b changed some internal state of builds, the one in c object will also be changed.

Is it possible to recreate this optional parameters each time by using this optional parameters syntax?

3 Answers
Related