Exercise 42 - class and instantiate
Posted petitherisson
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Exercise 42 - class and instantiate相关的知识,希望对你有一定的参考价值。
## Animal is-a object (yes, sort of confusing) look at the extra credit
class Animal(object):
pass
## ??
class Dog(Animal):
def __init__(self, name):
## ??
self.name = name
## ??
class Cat(Animal):
def __init__(self, name):
## ??
self.name = name
## ??
class Person(object):
def __init__(self, name):
## ??
self.name = name
## Person has-a pet of some kind
self.pet = None
## ??
class Employee(Person):
def __init__(self, name, salary):
## ?? hmm what is this strange magic?
super(Employee, self).__init__(name)
## ??
self.salary = salary
## ??
class Fish(object):
pass
## ??
class Salmon(Fish):
pass
## ??
class Halibut(Fish):
pass
## rover is-a Dog
rover = Dog("Rover")
## ??
satan = Cat("Satan")
## ??
mary = Person("Mary")
## ??
mary.pet = satan
## ??
frank = Employee("Frank", 120000)
## ??
frank.pet = rover
## ??
flipper = Fish()
## ??
crouse = Salmon
## ??
harry = Halibut()
2019-10-01
23:51:14
以上是关于Exercise 42 - class and instantiate的主要内容,如果未能解决你的问题,请参考以下文章
CF516DDrazil and Morning Exercise
CF516D Drazil and Morning Exercise