How do i print out all the contents in op list? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How do i print out all the contents in op list?

https://code.sololearn.com/cpo6Cr3yyXlA/?ref=app

29th Mar 2022, 11:05 AM
Lenoname
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)
29th Mar 2022, 4:54 PM
Stefanoo
Stefanoo - avatar
+ 1
print the owner name as well
29th Mar 2022, 1:40 PM
Slick
Slick - avatar
+ 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().
29th Mar 2022, 2:34 PM
Slick
Slick - avatar
0
by printing the values like normal. https://code.sololearn.com/ckmRuDsmVpA5/?ref=app
29th Mar 2022, 11:25 AM
Slick
Slick - avatar
0
Slick its not showing the results, it says [<__main__……
29th Mar 2022, 11:38 AM
Lenoname
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
29th Mar 2022, 11:46 AM
Slick
Slick - avatar
0
Slick change the dunder to what? How do i access each object? For a in op: print(a.owner, a.pet) doesnt work.
29th Mar 2022, 12:00 PM
Lenoname
0
What kind of dunder? __repr__?
29th Mar 2022, 12:01 PM
Lenoname
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.
29th Mar 2022, 12:43 PM
Slick
Slick - avatar
0
How can i see all the owners plus their pets?i mean in your code⬆️
29th Mar 2022, 1:39 PM
Lenoname
0
print(owner.name,owner.lastname,owner.pets) Output jamat son [<__main__.Animal object at 0x7fa2dd727fa0>, <__main__.Animal object at 0x7fa2dd772bb0>]
29th Mar 2022, 2:00 PM
Lenoname
- 1
Nevermind, just tell me how to print out op in my code, if its possible, otherwise thanks anyway
29th Mar 2022, 3:18 PM
Lenoname