menu

Questions & Answers

Copied code from w3schools and it produces an error in my python terminal
"""
Parent Class: The class being inherited from
Child Class: Inherits from the parent class.
"""

class Person:
    def __int__(self, fname, lname):
        self.firstname = fname
        self.lastname = lname

    def printName(self):
        print(self.firstname, self.lastname)

x = Person("John", "Smith")
x.printName()

So I am currently using w3schools to touch up on my python skills. I copied the following code from the website into my pycharm terminal, but I keep getting an error saying that the Person class does not take any arguments. What is going on here.

Comments:
2023-01-22 00:30:11
The webpage has a typo. It is __init__, not __int__.
2023-01-22 00:30:11
@MichaelM. It's probably this webpage. I don't see the typo on it.
Answers(0) :