Reputation: 1
Hi I am new to python and just trying to get my way through to Python and I have created a class and created two methods under it but i don't understand why the below code does not work. Any help please?
FYI i am using jupyter notebook
class student:
clg='xyz' #class variable
def _init_(self,rollno,name):
self.rollno=rollno
self.name=name
def display(self):
print('student name',self.name)
print('student roll no',self.rollno)
print('student college',student.clg)
student1 = student('xyz001',"ajay")
student1.display()
TypeError Traceback (most recent call last)
<ipython-input-36-4ae2a2de8a8b> in <module>()
10 print('student college',student.clg)
11
---> 12 student1 = student('xyz001',"ajay")
13 student1.display()
TypeError: object() takes no parameters
Upvotes: 0
Views: 38
Reputation: 741
Very simple answer. Your '_init_'
must have double underscores on either side, like this: __init__
Upvotes: 1