This is probably a kinda commonly asked question but I could do with help on this. I have a list of class objects and I’m trying to figure out how to make it print an item from that class but rather than desplaying in the;
<__main__.evolutions instance at 0x01B8EA08>
but instead to show a selected attribute of a chosen object of the class. Can anyone help with that?
If you want to just display a particular attribute of each class instance, you can do
Which will print out the
attrattribute of each object in the listmy_list_of_objs. Alternatively, you can define the__str__()method for your class, which specifies how to convert your objects into strings: