Two examples;
class Foo1:
something = 0
def __init__(self, n):
self.something = n
and
class Foo2:
def __init__(self, n):
self.something = n
Both classes seem to have the same behaviour:
x = Foo1(42)
y = Foo2(36)
print x.something
# will print 42
print y.something
# will print 36
But in the class Foo1
is the variable self.something
(in the constructor) actually the variable something
as defined at the beginning of the class? What is the difference here? Which way is preferred to use?