Review Python BASICS (10)

Source: Internet
Author: User

1. I learned some concepts today. (Book 41st ~ Chapter 43)

This method can be used to distinguish between class, object,Instance

## Animal is-a object (yes, sort of confusing) look at the extra creditclass Animal(object):    pass## Dog is-a animal, it has-a nameclass Dog(Animal):    def __init__(self, name):        ## ??        self.name = name## Cat is-a animal, it has-a nameclass Cat(Animal):    def __init__(self, name):        ## ??        self.name = name## Person is-a object, it has-a name and petclass Person(object):    def __init__(self, name):        ## ??        self.name = name        ## Person has-a pet of some kind        self.pet = None## Employee is-a Person, it has-a name and salaryclass Employee(Person):    def __init__(self, name, salary):        ## ?? hmm what is this strange magic?        super(Employee, self).__init__(name)        ## ??        self.salary = salary## Fish is-a objectclass Fish(object):    pass## Salmon is-a Fishclass Salmon(Fish):    pass## Halibut is-a Fishclass Halibut(Fish):    pass## rover is-a Dogrover = Dog("Rover")## satan is-a Catsatan = Cat("Satan")## mary is-a Personmary = Person("Mary")## mary has-a pet, satanmary.pet = satan## frank is-a employee, it has-a salary 120000frank = Employee("Frank", 120000)## frank has-a pet, roverfrank.pet = rover## flipper is-a fishflipper = Fish()## crouse is-a salmoncrouse = Salmon()## harry is-a halibutharry = Halibut()

In this way, you can clearly understand the concepts of objects, classes, and instances.

2. Oop

  1. Write or draw about the problem.
  2. Extract key concepts from #1 and research them.
  3. Create a class hierarchy and object map for the concepts.
  4. Code the classes and a test to run them.
  5. Repeat and refine.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.