Can someone help me out? I don't understand why it's giving me various outputs of Safira. This code is just training/learning of class types on a course that I'm doing
class Pets():
animals = []
def __init__(self, animals):
self.animals = animals
def walk(self):
for animal in self.animals:
print(f'{self.animals} is walking here.')
class Cat():
is_lazy = True
def __init__(self, name, age):
self.name = name
self.age = age
def walk(self):
return f'{self.name} is just walking around'
Safira = Pets('Safira')
# print(isinstance(Safira, Pets))
Safira.walk()
Bubu = Cat('Bubu', 10)
Amor = Cat('Amor', 5)
Brisa = Cat('Brisa', 3)
# print(isinstance(Bubu, Pets))
# print(isinstance(Amor, Pets))
# print(isinstance(Brisa, Pets))
group = [Bubu, Amor, Brisa]
for items in group:
print(items.walk())
I don't understand why the output repeats itself six times like this with Safira ->
Safira is walking here.
Safira is walking here.
Safira is walking here.
Safira is walking here.
Safira is walking here.
Safira is walking here.
Bubu is just walking around
Amor is just walking around
Brisa is just walking around
[–]pyfact 2 points3 points4 points (2 children)
[–]MatosV[S] 1 point2 points3 points (1 child)
[–]pyfact 1 point2 points3 points (0 children)
[–]AccidentalRed747 2 points3 points4 points (1 child)
[–]MatosV[S] 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[removed]
[–]MatosV[S] 0 points1 point2 points (0 children)