Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Print object attributes in python

# 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__())
Source by favtutor.com #
 
PREVIOUS NEXT
Tagged: #Print #object #attributes #python
ADD COMMENT
Topic
Name
9+4 =