+ 1
How do i print out all the contents in op list?
13 Answers
0
I think this is what you want
for a in op:
for o in a.owner:
print(o)
for p in a.pet:
print(p)
+ 1
print the owner name as well
+ 1
Yeah, you printed owner name. You can't just print the pets list though. You need to seperatly print each pet in a loop to get their string representation or create a method in the owner class that prints_pets().
0
by printing the values like normal.
https://code.sololearn.com/ckmRuDsmVpA5/?ref=app
0
Slick its not showing the results, it says [<__main__……
0
those are the results: class objects. You need to change the string dunder and/or access each object within the for loop to display the data saved to each class
0
Slick change the dunder to what? How do i access each object? For a in op: print(a.owner, a.pet) doesnt work.
0
What kind of dunder? __repr__?
0
Im also not sure about the owpet class. Why not just make an empty list called self.pets in the owner class? That way, you can just access an owner and print out each pet in the pet list. It seems overly complicated.
0
How can i see all the owners plus their pets?i mean in your code⬆️
0
print(owner.name,owner.lastname,owner.pets)
Output
jamat son [<__main__.Animal object at 0x7fa2dd727fa0>, <__main__.Animal object at 0x7fa2dd772bb0>]
- 1
Nevermind, just tell me how to print out op in my code, if its possible, otherwise thanks anyway