Class instances with no variables?

I was watching the great Python OOP tutorial by JimShapedCoding on the freecodecamp channel but one part really confused me Object Oriented Programming with Python - Full Course for Beginners - YouTube

At 1:00:10 he writes a class method to turn a csv to instances. The instances show up in the class but are they linked to variables, can you access them (or how can you access them), and is there a reason to do this instead of just using variables?

One reason could be convenience. For class with having dozens instances, assigning separate variable for each of them might not be needed or desired at all. Likely instances would be put into some data structure, which in this case is already handled by appending instance in __init__ to the list all being class variable.

Iā€™d approach this as a kind of showing what is possible, rather than something to follow every time.

Thank you. But how do you access these instances?

In here Item.all is list containing all instances. They can be accessed like any element within the list. For example with index Item.all[0], or when iterating over Item.all.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.