Access object within another objects in Python Last Updated : 20 Aug, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Prerequisite: Basics of OOPs in Python In this article, we will learn how to access object methods and attributes within other objects in Python. If we have two different classes and one of these defined another class on calling the constructor. Then, the method and attributes of another class can be accessed by first class objects ( i.e; objects within objects ). Here in the below example we learn to access object (its methods and attributes) within an object. We define two classes (class first and class second) with proper definitions. First class consists of a constructor and a method.The constructor form an object of the second class in the attribute of the first class.The method defines the presence in first class method.Similarly, the second class consists of a constructor and a method.The constructor form an attribute.The method defines the presence in the second class method. As the attribute of first class work as an object of the second class so all the methods and attributes of the second class can be accessed using this: object_of_first_class.attribute_of_first_class Below is the implementation: Python3 # python program to understand the # accessing of objects within objects # define class first class first: # constructor def __init__(self): # class second object # is created self.fst = second() def first_method(self): print("Inside first method") # define class second class second: # constructor def __init__(self): self.snd = "GFG" def second_method(self): print("Inside second method") # make object of first class obj1 = first() print(obj1) # make object of second class # with the help of first obj2 = obj1.fst print(obj2) # access attributes and methods # of second class print(obj2.snd) obj2.second_method() # This code is contributed # by Deepanshu Rustagi. Output: <__main__.first object at 0x7fde6c57b828> <__main__.second object at 0x7fde6c57b898> GFG Inside second method Comment More infoAdvertise with us Next Article How to Access dict Attribute in Python D deepanshu_rustagi Follow Improve Article Tags : Python python-oop-concepts Python-OOP Practice Tags : python Similar Reads Convert class object to JSON in Python In Python, class objects are used to organize complex information. To save or share this information, we need to convert it into a format like JSON, which is easy to read and write. Since class objects can't be saved directly as JSON, we first convert them into a dictionary (a data structure with ke 3 min read How to get the memory address of an object in Python In Python, everything is an object, from variables to lists and dictionaries everything is treated as objects. In this article, we are going to get the memory address of an object in Python. Method 1: Using id() We can get an address using the id() function. id() function gives the address of the pa 2 min read How to Access dict Attribute in Python In Python, A dictionary is a type of data structure that may be used to hold collections of key-value pairs. A dictionary's keys are connected with specific values, and you can access these values by using the keys. When working with dictionaries, accessing dictionary attributes is a basic function 6 min read How to Print Object Attributes in Python In Python, objects are the cornerstone of its object-oriented programming paradigm. An object is an instance of a class, and it encapsulates both data (attributes) and behaviors (methods). Understanding how to access and print the attributes of an object is fundamental for debugging, inspecting, and 2 min read Searching a list of objects in Python Searching for a single or group of objects can be done by iterating through a list. You might want to search a list of objects to find the object in the list of objects. It is very hard to look for objects manually, you can use the below-discussed method to search for objects in a list. You can also 3 min read Print Objects of a Class in Python In object-oriented programming (OOP), an object is an instance of a class. A class serves as a blueprint, defining the structure and behavior of objects, while an instance is a specific copy of the class with actual values. When an object is created, the class is said to be instantiated. All instanc 4 min read Like