Python 32 Programming Tutorial - Inheritance

class Parent():

    def print_last_name(self):
        print('Roberts')

    def print_skin_color(self):
        print('White')


class Child(Parent):

    def print_first_name(self):
        print('Bucky')

    # The child can also "override" a function that they inherited
    def print_last_name(self):
        print('Snitzleberg')


dad = Parent()
bucky = Child()

dad.print_last_name()
bucky.print_last_name()

你可能感兴趣的:(Python 32 Programming Tutorial - Inheritance)