class College():
def __init__(self,name):
self.name = name
def name(self):
print(self.name)
a = College("IIT")
a.name()
Advertisement
Answer
You are getting this because when you are calling the name() method but the program (python compiler) thinks that you are calling the name attribute of that object.
To prevent that from happening this just use a different name for every methods, attributes and variables.
class College():
def __init__(self,name):
self.name = name
def show_name(self):
print(self.name)
a = College("IIT")
a.show_name()