Program
|
Output
|
class Fruits:
def __init__(self, Fruitname, price):
self.Fruitname = Fruitname
self.price = price
def ourfunc (self):
print("Fruit Name: " + self.Fruitname)
print("Fruit Price: " + self.price)
p1 = Fruits("Apple", "20")
p1.ourfunc()
|
Fruit Name: Apple
Fruit Price: 20
|
class Fruits:
def __init__(obj1, Fruitname, price):
obj1.Fruitname = Fruitname
obj1.price = price
def ourfunc (obj1):
print("Fruit Name: " + obj1.Fruitname)
print("Fruit Price: " + obj1.price)
p1 = Fruits("Apple", "20")
p1.ourfunc()
|
Fruit Name: Apple
Fruit Price: 20
|
#Modify Object Properties
class Fruits:
def __init__(obj1, Fruitname, price):
obj1.Fruitname = Fruitname
obj1.price = price
def ourfunc (obj1):
print("Fruit Name: " + obj1.Fruitname)
print("Fruit Price: " + obj1.price)
p1 = Fruits("Apple", "20")
p1.ourfunc()
p1.price="90"
p1.ourfunc()
|
Fruit Name: Apple
Fruit Price: 20
Fruit Name: Apple
Fruit Price: 90
|
#Delete Object Properties using del keyword
class Fruits:
def __init__(obj1, Fruitname, price):
obj1.Fruitname = Fruitname
obj1.price = price
def ourfunc (obj1):
print("Fruit Name: " + obj1.Fruitname)
p1 = Fruits("Apple", "20")
p1.ourfunc()
del p1.price
p1.ourfunc()
|
Fruit Name: Apple
Fruit Name: Apple
|
#Delete Object using del keyword
class Fruits:
def __init__(obj1, Fruitname, price):
obj1.Fruitname = Fruitname
obj1.price = price
def ourfunc (obj1):
print("Fruit Name: " + obj1.Fruitname)
p1 = Fruits("Apple", "20")
p1.ourfunc()
del p1.price
p1.ourfunc()
del p1
|
|