Hi,
I am getting err “TypeError: init() takes 3 positional arguments but 4 were given” while using below code block (1st snippet).
Where as the 2nd block working fine. Not able to find out what went wrong. Need suggestion…
========== Snippet 1 ===========
class Person:
def __init__(self, name, age):
self.fname = name
self.curage = age
class Student2(Person):
def _init_(self, name, age, salary):
Person.__init__(self, name, age)
self.csalary = salary
def cprint(self):
print("Welcome", self.fname, "aged", self.curage, "in our company with a salary of", self.csalary)
y = Student2("Andrew", 32, 1000)
y.cprint()
========== Snippet 2 ===========
class Pers:
def __init__(self, fname, lname):
self.firstname = fname
self.lastname = lname
def persWel(self):
print(self. firstname, " ", self.lastname)
class Stu(Pers):
def __init__(self, fname, lname, year):
Pers.__init__(self, fname, lname)
self.graduationyear = year
def welcome(self):
print("Welcome", self.firstname, self.lastname, "to the class of", self.graduationyear)
x = Stu("Mike", "Olsen", 2019)
x.welcome()
x.persWel()
=============================
Note: Some of the syntax is getting lost while I submit the code snippet… like the preceding and trailing underscores around init.
Thanks,
Soumen