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)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

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
  2 errors in code numbnumb54 2 206 Jul-24-2020, 02:28 PM
Last Post: Marbelous
  Code errors rhyjom 0 241 Jun-21-2020, 04:50 PM
Last Post: rhyjom
  [split] Kera Getting errors when following code example Image classification from scratch hobbyist 2 360 Jun-14-2020, 01:53 PM
Last Post: hobbyist
  Errors in code coolcassie 2 331 Dec-03-2019, 12:10 AM
Last Post: coolcassie
  Errors trying to run code ziggyztz 3 513 Nov-03-2019, 04:24 AM
Last Post: newbieAuggie2019
  Decorator toy code throws syntax errors kevinxhi 3 1,249 Sep-04-2017, 03:01 AM
Last Post: kevinxhi

Forum Jump:


Users browsing this thread: 1 Guest(s)