Quantcast
Viewing all articles
Browse latest Browse all 77

Answer by kame for What is the purpose of the word 'self', in Python?

I like this example:

class A: 
    foo = []
a, b = A(), A()
a.foo.append(5)
b.foo
ans: [5]

class A: 
    def __init__(self): 
        self.foo = []
a, b = A(), A()
a.foo.append(5)
b.foo
ans: []

Viewing all articles
Browse latest Browse all 77

Trending Articles