{{tag>projects cloud club computing virtualization machines VMs AWS Azure GCP}}
[[python_club|About the Club]]\\
==== Python Club Topics - Classes & Objects ====
==== Questions ====
- What a class? A class is like a **__blueprint or template__** for **//creating objects//**. It defines the attributes (data) and methods (actions) that objects of that class will have. It is a logical entity and doesn't occupy memory space when declared.
- What an object? An object is an **__instance of a class__**. It's a concrete entity that exists in memory and has specific values for the attributes defined by its class. It's a physical entity that can be manipulated.
==== Class ====
- A class is a blueprint for creating objects
==== Class examples ====
- Define a basic class
class Dog:
def __init__(self, name, breed):
self.name = name
self.breed = breed
# Create an instance of the Dog class
my_dog = Dog("Buddy", "Golden Retriever")
# Access the attributes of the object
print(my_dog.name)
print(my_dog.breed)
- You **cannot** print an object directly like a list, tuple, or dictionary
class Dog:
def __init__(self, name, breed):
self.name = name
self.breed = breed
# Create an instance of the Dog class
my_dog = Dog("Buddy", "Golden Retriever")
# Access the attributes of the object
print(my_dog)
- Instead, you print all values of an object with the **_ _dict_ _** method
class Dog:
def __init__(self, name, breed):
self.name = name
self.breed = breed
# Create an instance of the Dog class
my_dog = Dog("Buddy", "Golden Retriever")
print(my_dog.__dict__)