Python - Practice
Creating classes and subclasses allows you to inherit both or override the other. By including the super.()__init__() attribute you can use both!
/Users/mattfassnacht/PycharmProjects/untitled6/venv/bin/python /Users/mattfassnacht/PycharmProjects/untitled6/prac3.py
test@person.com
None
Process finished with exit code 0
class Contact: def __init__(self, first_name, last_name): self.first_name = first_name self.last_name = last_name self.full_name = first_name + "" + last_name def print_contact(self): print(self.full_name) class EmailContact(Contact): def __init__(self, first_name, last_name, email): super().__init__(first_name, last_name) self.email = email self.full_name = email email_contact = EmailContact('test', 'person', "test@person.com") print(email_contact.print_contact())
/Users/mattfassnacht/PycharmProjects/untitled6/venv/bin/python /Users/mattfassnacht/PycharmProjects/untitled6/prac3.py
test@person.com
None
Process finished with exit code 0
Comments