I have two functions, fun1
and fun2
, which take as inputs a string and a number, respectively. They also both get the same variable, a
, as
Object-oriented programming helps here:
class MyClass(object):
def __init__(self):
self.a = ['A','X','R','N','L'] # Shared instance member :D
def fun1(self, string):
out = []
for letter in self.a:
out.append(string+letter)
return out
def fun2(self, number):
out = []
for letter in self.a:
out.append(str(number)+letter)
return out
a = MyClass()
x = a.fun1('Hello ')
y = a.fun2(2)