To print a list of class objects in Python, you can use the for loop, join() function, or ‘*’ operator. Let’s see how to perform them.
Print A List Of Class Objects In Python
To print a list of class objects, you have to print each attribute of the object in each iteration or override the __str__() method when creating the object first. Then, combined with the for loop, join() function or ‘*’ operator.
Using the for loop
A simple way to print a list of class objects in Python, you can use the for loop. It is used to iterate the loop and print out each element in the list.
Look at the example below.
# Create an object. class Club: def __init__(self, club, rank, point): self.name = club self.rank = rank self.point = point # Override def __str__(self): return self.name + ' ' + str(self.rank) + ' ' + str(self.point) # Create the list of objects. club1 = Club('MU', 1, 40) club2 = Club('ARS', 2, 39) club3 = Club('LIV', 3, 38) clubs = [club1, club2, club3] # Print a list of clubs with the for loop. for element in clubs: print(element)
Output
MU 1 40
ARS 2 39
LIV 3 38
Using the ‘*’ operator
If you want to print all elements of class objects that are one whitespace apart, you can use the ‘*’ operator.
Look at the example below.
# Create an object. class Club: def __init__(self, club, rank, point): self.name = club self.rank = rank self.point = point # Override def __str__(self): return self.name + ' ' + str(self.rank) + ' ' + str(self.point) # Create the list of objects. club1 = Club('MU', 1, 40) club2 = Club('ARS', 2, 39) club3 = Club('LIV', 3, 38) clubs = [club1, club2, club3] # Print a list of clubs with the '*' operator. print(*clubs)
Output
MU 1 40 ARS 2 39 LIV 3 38
Using the join() function
Besides, you can use the join() function to print a list of class objects with the specified distinction between two continuous elements. To perform it, you have to convert the object to the String first.
Look at the example below.
# Create an object. class Club: def __init__(self, club, rank, point): self.name = club self.rank = rank self.point = point # Override def __str__(self): return self.name + ' ' + str(self.rank) + ' ' + str(self.point) # Create the list of objects. club1 = Club('MU', 1, 40) club2 = Club('ARS', 2, 39) club3 = Club('LIV', 3, 38) clubs = [club1, club2, club3] # Convert the Club to the String. clubs = [str(x) for x in clubs] # Print a list of clubs with the join() function. print(' || '.join(clubs))
Output
MU 1 40 || ARS 2 39 || LIV 3 38
Summary
We have shown you how to print a list of class objects in Python in 3 ways. In our opinion, you should use the join() function because you can assign the specified distinction between two continuous elements with this function. We hope this tutorial is helpful to you. Thanks!

My name is Thomas Valen. As a software developer, I am well-versed in programming languages. Don’t worry if you’re having trouble with the C, C++, Java, Python, JavaScript, or R programming languages. I’m here to assist you!
Name of the university: PTIT
Major: IT
Programming Languages: C, C++, Java, Python, JavaScript, R