Write a python class to instantiate an object with two string attributes and write a function to return the list of attributes


Topic: Write a python class to instantiate an object with two string attributes and write a function to return the list of attributes

Solution

class Myclass:  
    def __init__(self, attr1, attr2):
        self.attr1 = attr1
        self.attr2 = attr2
    def get_attributes_list(self):  
         return [self.attr1, self.attr2]
dress = Myclass("pant","shirt")
dress.get_attributes_list()



List all Python Programs