Hey, can I print all attributes of an object at once? I think i’ve done this but im not sure it couldve been something else. example:
class Boy(object):
def __init__(self, name, age):
self.name = name
self.age = age
James = Boy('James', 18)
print(Boy.James) # Or something similiar
florian
#2
Sure, you can print almost everything.
Print an attribute of an instance of a class: print(james.name)
Print a representation of the whole instance: print(james)
Just play around with these in the REPL. See what print(Boy)
does.
1 Like
zedshaw
#3
Yep, and also add a repr function too:
3. Data model — Python 3.9.7 documentation.repr