Efficient way to print class values

Im looking for a efficient way to print all of the class variables from a class. I now use the following code, that works, but doesn’t really look efficient.

for i in range(0, x):

I was thinking of looping through the variables, so you would loop from 0 to x and from a to c. Im not sure how to access those variable names within the class. Any suggestion might be appreciated, thanks.

You could have all the variables in a list in the class definition and then loop through that list. Something like this:

for inst in ClassDef.AllInstances:
   for v in inst.ClassVariables:

You can use the vars() function to get the instance variables of a class object as a dictionary. Then you can loop through the keys and values in the dictionary to print them.
Solution :

class MyClass:
    def __init__(self, a, b, c):
        self.a = a
        self.b = b
        self.c = c

ClassData = [MyClass(1, 2, 3), MyClass(4, 5, 6), MyClass(7, 8, 9)]

for i in range(len(ClassData)):
    instance_vars = vars(ClassData[i])
    for var_name, var_value in instance_vars.items():
        print("{var_name}: {var_value}")

Thanks, will try this method!