class yourClass:
def __str__(self):
return "value" #replace value with what you want to print
an = Animal()
attrs = vars(an)
# {'kids': 0, 'name': 'Dog', 'color': 'Spotted', 'age': 10, 'legs': 2, 'smell': 'Alot'}
# now dump this in some way or another
print(', '.join("%s: %s" % item for item in attrs.items()))
# listing out all attributes of an object in Python
# create a class
class Student:
def __init__(self, name, id, age):
self.name = name
self.id = id
self.age = age
def info(self):
return f"Student name: {self.name} and id: {self.id} "
# class variable
var = 1
# creating object
s1 = Student("Mradula", 1, 20)
s2 = Student("Joel", 2, 15)
print(s1.info())
print(s1.__dir__())
# listing out all attributes of an object in Python
# create a class
class Student:
def __init__(self, name, id, age):
self.name = name
self.id = id
self.age = age
def info(self):
return f"Student name: {self.name} and id: {self.id} "
# class variable
var = 1
# creating object
s1 = Student("Mradula", 1, 20)
s2 = Student("Joel", 2, 15)
print(s1.info())
print(s1.__dir__())