What happens when multiple attributes have same name in python ?

Python hide n seek !!!

What happens when instance attributes and methods have same name?

Look at this example

class Exam(object):

    test = "This is class var"

    def test(self):
        print "This is a method"

test_o = Exam()

print Exam.test
test_o.test()

Exam.test suppose to print "This is class var" but it won't, why?
Since both class attribute "test" and instance attribute names are same, instance attribute hides class attribute.
So never use same names for multiple attributes.

Tats Fine, what happens when instance var and methods name are same?

Look at below example

class Exam(object):

    def __init__(self, val):
        self.test = val

    def test(self):
        print "This is a method"

test_o = Exam("Instance var")
print Exam.test
test_o.test()

Exam.test --> outputs <unbound method Exam.test>
test_o.test() --> throws error TypeError: 'str' object is not callable

So never use same names for multiple attributes.

There is a question related to this topic, which i encountered and got answer in stackoverflow > stackoverflow question