Python Forum

Full Version: errors in code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm getting a TypeError. I want to call out my initialised parameters

Code:
class Students:
	def _init_(self, name,age,grade):
		self.name = name
		self.age = age
		self.grade = grade

		
student1 = Students("Bob", 12, "7th")
Error:
Error:
Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> student1 = Students("Bob", 12, "7th") TypeError: this constructor takes no arguments
it should be __init__, not _init_, i.e. double vs single underscore on both sides (before/after)
The class name should also be singular - what it defines is the type of a single kind of thing, not a collection of them.
I am very grateful