Python is an object-oriented programming language that supports the following key concepts:

1. Classes and Objects

2. Encapsulation

3. Inheritance

4. Polymorphism

5. Abstraction

Example:

Below is an example demonstrating the use of classes and objects in Python:

python class Person: def __init__(self, name, age): self.name = name self.age = age def display_info(self): print(f"Name: {self.name}, Age: {self.age}") # Creating objects of the Person class person1 = Person("Alice", 30) person2 = Person("Bob", 25) # Accessing object attributes and methods person1.display_info() person2.display_info()

In this example, the Person class defines attributes name and age along with a method display_info() to display the information of a person. Two objects person1 and person2 are created from the class and their details are displayed using the display_info() method.

Back to Blog

Comments

No comments yet. Be the first to share your thoughts!