Q:

Operation on object makes changes on others

I need a little explanation. Operation on one object makes changes on others, for example:
aa = Classifier("aa")
bb = Classifier("bb")

aa.print_table()
{1: 6, 2: 26}

bb.print_table()
{1: 6, 2: 26}

aa.addValue(3)

bb.print_table()
{1: 6, 2: 26, 3: 1}

Here is part of my class:
class Classifier:

classTable = {1:0} 
default = 0
classTable_size = 0
def __init__(self, q):
    a = 1
    self.name = q

def addValue(self, i_index):
    self.classTable.setdefault(i_index, self.default)
    self.classTable[i_index] += 1
    self.classTable_size += 1

def print_table(self):
    print(self.classTable)

If I define variable on the top of class (before constructor in this case) it will makes it "static" or I have error in my class? I was thinking defining variables this way makes them only available from own object.
I am very new in python. 

A:

example:
class A:

    data = {}

    def __str__(self):
        return str(self.data)

class B:

    data = {}

    def __init__(self):

        self.data = {'B': 5}

    def __str__(self):
        return str(self.data)

in class A an instance does not own a data on its own; it is 'static' and can be accessed with self.data as well as A.data (that is how python looks up variables in an object: if self.data does not exist, python will look for A.data); both reference the same dictionary. changes to self.data (or A.data) will affect all instances:
a = A()
a.data.update({'A': 3})
print(a)  # -> {'A': 3}
aa = A()
print(aa)  # ->  {'A': 3}

except if you add a fresh data member for an instance; this one will belong to the instance only:
aa.data = {}  # data references now this empty dict and not A.data anymore
print(a)  # -> {}
print(aa) # -> {'A': 3}

in class B every instance gets its own fresh dict in the 'constructor' 
__init__ -- even if there is a 'static' data member. changes in one instance do not affect other instances. self.data is now a different object than B.data.
usually it is a bad idea to have a class variable (B.data) and an instance variable (self.data) with the same name...
maybe this is worth reading. and there is a lot more information about python out there...

