Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Class Error
#1
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
Reply
#2
You need double underscores not single,
Change this def _init_ to this def __init__.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  error in class non_name092 1 1,905 Sep-02-2020, 05:42 PM
Last Post: bowlofred
  My class has name error message 357mag 3 2,314 Sep-04-2019, 03:29 PM
Last Post: snippsat
  Error Type: <class 'OSError'> And Error Type: <class 'ValueError'> runnerpaul 1 3,660 Jul-18-2017, 03:08 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020