Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e11eeb0

Browse files
Python OOPS concept explained
1 parent 41f4648 commit e11eeb0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎OOPS.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Human:
2+
# attributes
3+
def __init__(self, name, height, weight):
4+
self.name = name
5+
self.height = height
6+
self.weight = weight
7+
8+
# behaviours
9+
def eating(self, food):
10+
return ("{} is eating {}".format(self.name, food))
11+
12+
13+
# creating objects
14+
ram = Human("Ram", 6, 60)
15+
praveen = Human("Praveen", 5.9, 56)
16+
arun=Human("Arun",6.0,50)
17+
18+
# printing object information
19+
print("Height of {} is {}".format(ram.name, ram.height))
20+
print("Weight of {} is {}".format(ram.name, ram.weight))
21+
print(ram.eating("Pizza"))
22+
print("Weight of {} is {}".format(praveen.name, praveen.height))
23+
print("Weight of {} is {}".format(praveen.name, praveen.weight))
24+
print(praveen.eating("Banana"))
25+
print("Weight of {} is {}".format(arun.name, arun.height))
26+
print("Weight of {} is {}".format(arun.name, arun.weight))
27+
print(arun.eating("Rice"))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /