Breadth-First and depth-first in Python

Source: Internet
Author: User

Python is divided into classic and modern classes:

Classic class:

Class A ():

Pass

New class:

Class A (object):

Pass

So the difference between a classic class and a new class is that when declaring a class, the new class needs to be prefixed with the object keyword.

The difference between classic and modern classes in Python:

The difference is mainly embodied in inheritance:

Python classes can inherit multiple classes, and Java and C # can inherit only one class

If a Python class inherits more than one class, there are two ways to find the method

When a class is a classic class, multiple inheritance cases are searched in the depth-first way

When a class is a new class, in multiple inheritance cases, the breadth-first method is found

The simple point is: The Classic class is a portrait search, the new class is landscape search

1 Classic class:2 classLife ():3     defdaily (self):4         Print "Multiply"5 6 classAnimal (Life):7     defdaily (self):8         Print "Eat"9         Print "Drink"Ten         Print "Pull" One         Print "Isaac" A  - classPuru (Life): -     def __init__(self): the         Pass -  - classCat (puru,animal): -     def __init__(self): +         Print "Meow Meow" -  +A =Cat () A a.daily () at  -  - the execution results are: -  - Meow Meow - Multiply in  - New class: to classLife (object): +     defdaily (self): -         Print "Multiply" the  * classAnimal (Life): $     defdaily (self):Panax Notoginseng         Print "Eat" -         Print "Drink" the         Print "Pull" +         Print "Isaac" A  the classPuru (Life): +     def __init__(self): -         Pass $  $ classCat (puru,animal): -     def __init__(self): -         Print "Meow Meow" the  -A =Cat ()Wuyi a.daily () the  - the execution results are: Wu  - Meow Meow About Eat $ Drink - Pull -Sub

Breadth-First and depth-first in Python

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.