Python Forum

Full Version: Creating Classes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
>>> 
I can't reproduce the error:

>>> class Students:
...     def __init__(self, name, age):
...         self.name = name
...         self.age = age
...
>>> st = Students("Bob", 15)
>>>
Your __init__() function name is wrong, Nothing else...
i corrected my mistake def _init(self,name,age) as def _init_(self,name,age)
and still getting the same error
You have to write double underscore before and after init.
Big Grin
done . thanks Wink