'Why while running the program I am getting object not callable

class College():
    
    def __init__(self,name):
        self.name = name
        
    def name(self):
        print(self.name)
        
a = College("IIT")
a.name()


Solution 1:[1]

You gave a an instance attribute named name when you called College.__init__. That shadows the class attribute (i.e., the method) with the same name. Choose a different method or attribute name.

a.name is the string "IIT", which is not callable. You can cheat a bit to get access to the method

>>> College.name(a)
IIT

but it will be cleaner to use separate names for the two attributes.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 chepner