Yas Yas - 17 hours ago 2
Python Question

object() takes no parameters - Python

I have written this simple code in python which I am running under conda virtual environment python version 3.6.

class Student:
def __int__(self,name,grade):
self.name = name
self.grade = grade


kitty = Student('Kitty',85)
danial = Student('Danial',80)

print(kitty.name)
print(danial.name)


When I run this code:

(snakes) dyn124101:RecSys_code PYTHON yas$ python demo_learning_python.py


I receive the following error message:

Traceback (most recent call last):
File "demo_learning_python.py", line 7, in <module>
kitty = Student('Kitty',85)
TypeError: object() takes no parameters


At first, I was suspicious that this is an indentation problem. I have tried to play around with the indentation of the code but so far the error remains. How can I solve this problem? Thanks

Answer

You have a typo, you wrote __int__ instead of __init__.