Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating Classes
#1
my question here

i am very new to python and need your help in below error message

my code here
========================================================
Python 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> class Students:
	def _init(self,name,age):
		self.name = name
		self.age =age

		
>>> stu1 = Students("Bob" , 15)
Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    stu1 = Students("Bob" , 15)
TypeError: object() takes no parameters
>>> 
Reply
#2
I can't reproduce the error:

>>> class Students:
...     def __init__(self, name, age):
...         self.name = name
...         self.age = age
...
>>> st = Students("Bob", 15)
>>>
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
Your __init__() function name is wrong, Nothing else...
Reply
#4
i corrected my mistake def _init(self,name,age) as def _init_(self,name,age)
and still getting the same error
Reply
#5
You have to write double underscore before and after init.
Big Grin
Reply
#6
done . thanks Wink
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating function inside classes using type wolfmansbrother 3 2,288 Mar-20-2020, 01:21 AM
Last Post: wolfmansbrother
  Using classes? Can I just use classes to structure code? muteboy 5 4,982 Nov-01-2017, 04:20 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

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