Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 errors in code
#1
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
buran wrote Jul-19-2019, 10:54 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Quote
#2
it should be __init__, not _init_, i.e. double vs single underscore on both sides (before/after)
Quote
#3
The class name should also be singular - what it defines is the type of a single kind of thing, not a collection of them.
Quote
#4
I am very grateful
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Errors in code coolcassie 2 125 Dec-03-2019, 12:10 AM
Last Post: coolcassie
  Errors trying to run code ziggyztz 3 206 Nov-03-2019, 04:24 AM
Last Post: newbieAuggie2019
  Decorator toy code throws syntax errors kevinxhi 3 935 Sep-04-2017, 03:01 AM
Last Post: kevinxhi

Forum Jump:


Users browsing this thread: 1 Guest(s)