Optional parameter object re-used when instantiating multiple objects

Rick Giuly rgiuly.group at yahoo.com
Sat Nov 15 10:40:04 CET 2008

Hello All,

Why is python designed so that b and c (according to code below)
actually share the same list object? It seems more natural to me that
each object would be created with a new list object in the points

class Blob:
    def __init__(self, points=[]):
        self._points = points

b = Blob()
c = Blob()


print b._points

# this will show that b._points is the same object as c._points

More information about the Python-list mailing list