53.1.1. Methods - An overview
(a) Methods are a set of statements that are called to perform a specific task.
(b) Methods are used in OOPS.
53.1.2. Writing a program with methods
class Person:
#fill in the missing code
def setName(self,name):
self.name = name
def getName(self):
return(self.name)
p1 = Person()
p2 = Person()
name1 = input('p1 name: ')
name2 = input('p2 name: ')
p1.setName(name1)
p2.setName(name2)
print("p1 name:",p1.getName())
print("p2 name:",p2.getName())
53.1.3. Python's way of method overloading
class Greeting:
def sayHello(self, name=None, wish=None):
if wish == None:
print("Hello"+name)
else:
print("Hello"+name+wish)
#write your code here....
a = input()
b = input()
greet = Greeting()
greet.sayHello(a)
greet.sayHello(a,b)