Python Forum

Full Version: Class Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
class Students:
    def _init_(self,name,age,grade):
        self.name = name
        self.age = age
        self.grade = grade

student1 = Students("Bob", 12, "7th")
print(student1.name)
I only want the student's name to get printed yet it is not working :
Error:
File "C:\Users\ohh05\Desktop\tet3.py", line 7, in <module> student1 = Students("Bob", 12, "7th") TypeError: object() takes no parameters
You need double underscores not single,
Change this def _init_ to this def __init__.