Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Liquid Web Managed Dedicated Server: RAID 1 SSD with 16GB of RAM minimum! 24/7 On-Site Heroic Support! Industry-Leading SLA!

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Liquid Web Cloud VPS Hosting

8,548 questions

11,834 answers

573 users

How to use inheritance in Python

2 Answers

0 votes
class Person:
    def __init__(self, first_name_, last_name_):
        self.first_name = first_name_
        self.last_name = last_name_

    def fullname(self):
        return self.first_name + " " + self.last_name


class Person:
    def __init__(self, first_name_, last_name_):
        self.first_name = first_name_
        self.last_name = last_name_

    def fullname(self):
        return self.first_name + " " + self.last_name


class Programmer(Person):

    def __init__(self, first_name_, last_name_, language_):
        Person.__init__(self, first_name_, last_name_)
        self.language = language_

    def details(self):
        return self.fullname() + ": " + self.language

per = Person("Tom", "Bix")
pro = Programmer("R2", "D2", "Python")

print(per.fullname())
print(pro.details())


'''
run:

Tom Bix
R2 D2: Python

'''

 




answered Feb 11 by avibootz
0 votes
class Person:
    def __init__(self, first_name_, last_name_, age_):
        self.first_name = first_name_
        self.last_name = last_name_
        self.age = age_

    def fullname(self):
        return self.first_name + " " + self.last_name

    def __str__(self):
        return self.first_name + " " + self.last_name + " - " + str(self.age)


class Programmer(Person):

    def __init__(self, first_name_, last_name_, age_, language_):
        super().__init__(first_name_, last_name_, age_)
        self.language = language_

    def __str__(self):
        return super().__str__() + ": " + self.language

per = Person("Tom", "Bix", 46)
pro = Programmer("R2", "D2", 39, "Python")

print(per)
print(pro)

'''
run:

Tom Bix - 46
R2 D2 - 39: Python

'''

 




answered Feb 11 by avibootz
...