Andromeda
Note

Objects (Python)

Definition

An Object is a specific instance created from a Class blueprint in Python. It is an independent entity that holds its own distinct data (attributes) while sharing the behaviors (methods) defined by its class.

Why It Matters

Objects are the “actors” in a program. By instantiating multiple objects from a single class, developers can represent collections of distinct entities (like 100 different ‘User’ objects) that behave consistently without duplicating logic.

Core Concepts

  • Instantiation: The process of creating a specific object from a class definition (e.g., my_dog = Dog('Fido')).
  • Instance Attributes: Data belonging specifically to one instantiated object, accessed via dot notation (e.g., my_dog.name).
  • Method Invocation: Calling a function attached to the object, where the object implicitly passes itself as the self argument (e.g., my_dog.sit()).
class Dog:
    def __init__(self, name):
        self.name = name
    
    def bark(self):
        print(f"{self.name} says woof!")

# Instantiation (Creating an object)
my_dog = Dog("Fido")
my_dog.bark()  # Method invocation

Connected Concepts