OOP Question [ SOLVED ] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

OOP Question [ SOLVED ]

I have a code with a class and many objects created from it. There are many objects and I want to print them altogether using a function. Can anybody tell me how can this be done?? Here's that code: https://code.sololearn.com/cU7TI6AjVY09/?ref=app First there is a function dec() for printing a line, next is info() to print the parameters and after that is call() to call the both functions above. But using call() I have to call the function as many times as the objects. So I want to create a function that includes call() and prints all the objects as well.

24th May 2022, 7:13 AM
Aurora Borealis
Aurora Borealis - avatar
5 Answers
+ 3
Comment line 32 and see..
25th May 2022, 9:05 AM
Jayakrishna 🇮🇳
+ 4
Put all objects in the same list, loop through the list
24th May 2022, 7:38 AM
Lisa
Lisa - avatar
+ 3
glxy = [Galaxy('A'), Galaxy('B')] for g in glxy: print(g.name)
25th May 2022, 7:05 AM
Lisa
Lisa - avatar
+ 3
Jayakrishna🇮🇳 Thanks !! 😊
25th May 2022, 9:08 AM
Aurora Borealis
Aurora Borealis - avatar
+ 1
Lisa what do you mean by 'loop through the list'? Is it writing the index of objects??
25th May 2022, 4:00 AM
Aurora Borealis
Aurora Borealis - avatar