Exploring Object-Oriented Programming with Baahubali: A Python Class Example

Tejaksha K
3 min readMar 9, 2023

--

Python classes are a fundamental concept in object-oriented programming that allow developers to create reusable code structures. They can be used to represent real-world objects or concepts in a program, such as a person, car, or animal. To better understand this concept, let’s explore the story of Baahubali, a fictional Indian historical film.

In the movie Baahubali, the story revolves around two brothers, Baahubali and Bhallaladeva, who are competing for the throne of the Mahishmati kingdom. Baahubali is known for his strength, bravery, and his ability to inspire others, while Bhallaladeva is known for his cunningness, ruthlessness, and desire for power. To represent these two characters as Python objects, we can use classes.

Let’s start with the Baahubali class:

class Baahubali:
def __init__(self, name, strength, bravery, charisma):
self.name = name
self.strength = strength
self.bravery = bravery
self.charisma = charisma

def inspire(self):
print(f"{self.name} inspires his people to be brave and fight for their freedom.")

In this class, we define the properties of Baahubali, such as his name, strength, bravery, and charisma. We also define a method called inspire, which represents his ability to motivate and inspire others. This method can be called on an instance of the Baahubali class to simulate the character inspiring his people.

Now let’s create a class for Bhallaladeva:

class Bhallaladeva:
def __init__(self, name, strength, cunningness, ruthlessness):
self.name = name
self.strength = strength
self.cunningness = cunningness
self.ruthlessness = ruthlessness

def plot(self):
print(f"{self.name} plans to eliminate his brother and seize the throne for himself.")

In this class, we define the properties of Bhallaladeva, such as his name, strength, cunningness, and ruthlessness. We also define a method called plot, which represents his tendency to scheme and plot against his brother. This method can be called on an instance of the Bhallaladeva class to simulate the character plotting against his brother.

Now that we have defined the Baahubali and Bhallaladeva classes, we can create instances of these classes to represent the two characters:

baahubali = Baahubali("Baahubali", 100, 95, 90)
bhallaladeva = Bhallaladeva("Bhallaladeva", 90, 100, 95)

In these lines of code, we create instances of the Baahubali and Bhallaladeva classes, passing in the relevant properties for each character.

We can now call the inspire method on the baahubali instance to simulate the character inspiring his people:

baahubali.inspire()

This will output the following message:

Baahubali inspires his people to be brave and fight for their freedom.

Similarly, we can call the plot method on the bhallaladeva instance to simulate the character plotting against his brother:

bhallaladeva.plot()

This will output the following message:

Bhallaladeva plans to eliminate his brother and seize the throne for himself.

In conclusion, Python classes are a powerful tool in object-oriented programming that allow developers to define reusable code structures. The story of Baahubali can be used to illustrate this concept in a fun and engaging way. By representing the characters as Python objects, we can better understand how classes can be used to define the properties and behaviors of objects in a program. The Baahubali class represents the inspiring and heroic character, while the Bhallaladeva class represents the cunning and scheming character. Each class defines unique properties and behaviors that make the characters distinct and memorable. By exploring simple examples like these, developers can build a strong foundation in object-oriented programming and gain the skills needed to create more complex and dynamic programs.

You’re welcome! I’m glad I could help you with my blog post. Don’t hesitate to reach out if you have any other questions or need further assistance. Keep up the great work! ❤️

--

--

Tejaksha K
Tejaksha K

Written by Tejaksha K

I'm a Full Stack Developer & Cloud Expert with experience in Google Cloud Platform & AWS.

No responses yet