All Courses

Python Design Patterns - Object Oriented

Neha Kumawat

3 years ago

Python Insideaiml
Table of Content
  • How to implement the object oriented pattern?
  • Output
  • Explanation
           The object oriented pattern is the most commonly used pattern. This pattern can be found in almost every programming language.

How to implement the object oriented pattern?

     Let us now see how to implement the object oriented pattern.

class Parrot:
   # class attribute
   species = "bird"
   # instance attribute
   def __init__(self, name, age): = name
      self.age = age
# instantiate the Parrot class
blu = Parrot("Blu", 10)
woo = Parrot("Woo", 15)

# access the class attributes
print("Blu is a {}".format(blu.__class__.species))
print("Woo is also a {}".format(woo.__class__.species))

# access the instance attributes
print("{} is {} years old".format(, blu.age))
print("{} is {} years old".format(, woo.age))


The above program generates the following output


               The code includes class attribute and instance attributes, which are printed as per the requirement of the output. There are various features that form part of the object oriented pattern. The features are explained in the next chapter.
Like the Blog, then Share it with your friends and colleagues to make this AI community stronger. 
To learn more about nuances of Artificial Intelligence, Python Programming, Deep Learning, Data Science and Machine Learning, visit our insideAIML blog page.
Keep Learning. Keep Growing. 

Submit Review