Object Oriented Programming
Object Oriented Programming
Programming
Object Oriented Programming
Python is a multi-paradigm
programming language. It
supports different programming
approaches.
One of the popular approaches
to solve a programming problem
is by creating objects. This is
known as Object-Oriented
Programming (OOP).
An object has two characteristics:
attributes
behavior
print("Blu is a
# class attribute {}".format(blu.__class__.species))
species = "bird" print("Woo is also a
{}".format(woo.__class__.species))
# instance attribute
# access the instance attributes
def __init__(self, name,
age):
print("{} is {} years
self.name = name old".format( blu.name, blu.age))
self.age = age print("{} is {} years
old".format( woo.name, woo.age))
def __init__(self):
self.__maxprice = 900 Output
def sell(self):
Selling Price:
print("Selling Price: 900
{}".format(self.__maxprice))
Selling Price:
def setMaxPrice(self, price):
self.__maxprice = price
900
Selling Price:
c = Computer()
c.sell() 1000
# change the price
c.__maxprice = 1000
c.sell()