Python multiple inheritance 👨‍👩‍👧‍👦

preview_player
Показать описание
python multiple inheritance tutorial example explained

#python #multiple #inheritance

# -----------------------------------------------------------------------------
# multiple inheritance = when a child class is derived from more than one parent class

class Prey:

def flee(self):
print("This animal flees")

class Predator:

def hunt(self):
print("This animal is hunting")

class Rabbit(Prey):
pass

class Hawk(Predator):
pass

class Fish(Prey, Predator):
pass

rabbit = Rabbit()
hawk = Hawk()
fish = Fish()

# -----------------------------------------------------------------------------

Bro Code merch store 👟 :
===========================================================
===========================================================
Рекомендации по теме
Комментарии
Автор

# multiple inheritance = when a child class is derived from more than one parent class

class Prey:

def flee(self):
print("This animal flees")

class Predator:

def hunt(self):
print("This animal is hunting")

class Rabbit(Prey):
pass

class Hawk(Predator):
pass

class Fish(Prey, Predator):
pass


rabbit = Rabbit()
hawk = Hawk()
fish = Fish()

# rabbit.flee()
# hawk.hunt()
fish.flee()
fish.hunt()

BroCodez
Автор

Big thank you Bro Code. Great presentation!!

hueyd
Автор

I am from Venezuelan and I am grateful for your work. Thanks, bro

alfredoaristizabal
Автор

The immediate question that comes up seeing both Prey and Preditor classes is what happens if they both define something like `sleep`. Really should be at least hinted at in an introduction.

LanceGliser
Автор

Great explanation Bro, ,, keep up the great work :)

xplatform
Автор

Hey Bro Code, i'm usually not commenting, just started learning 2 days ago from your courses, and using the occasion - I love it, thank you!, but on this one I had to!
You say that you don't know any predator rabbits... You can say that in Java course, or any other course, but surely you cannot say this in Python courses! (Remember the rabbit scene at the Monty Python and the Holy Grail?) :D

dudik
Автор

"Sit back, relax, and smoke some crack!"

aaroncatolico
Автор

You should have more subscribers bro.

I'm sure that these videos are blowing up down the road sooner or later.

RipperRoo
Автор

if all the outputs are "This animal is doing this, this animal is doing that", we don't know from which animal we are talking about.
So how, instead of saying "This animal is hunting", do we say "This "+[hawk, fish, rabbit, whataver]+" is hunting".
How do we put the name of a lower class into a higher class?

cdemr
Автор

What if both Prey class and Predator class have one method with same name, but print differently?

wingsonlai
Автор

Hi friend, don't just show the code, also show the output please. Hola amigo, no muestre solo el código, también muestra la salida por favor.

Henry_Nunez
Автор

My output shows an error: [Errno 2] No such file or directory
Can you help me fix it ?

thucanhvu
Автор

Bro code:
"I don't know if there are any predator rabbits out there"

Me:
* 𝗜𝗻𝘁𝗲𝗻𝘀𝗲 𝗿𝗲 𝘇𝗲𝗿𝗼 𝗳𝗹𝗮𝘀𝗵𝗯𝗮𝗰𝗸𝘀

LuvGaddamwarXD
join shbcf.ru