def functionCreator(txt):
def createdFunction(newTxt):
return txt + " " + newTxt
return createdFunction
print(functionCreator("hello")("world"))
# Here we define the function with a parameter
def greet(lang):
if lang == 'spanish':
print('Hola!')
elif lang == 'french':
print('Bonjour!')
else:
print('Hello!')
# Now we can call or invoke the function with different parameters
greet('spanish') # Output - Hola!
greet('french') # Output - Bonjour!
greet('english') # Output - Hello!
def sum(a,b):
return a+b
def calculate(function,a,b):
return function(a,b)
calculate(sum,3,4)
#returns 7
def shout(text):
return text.upper()
print(shout('Hello World'))
yell = shout
print(yell('Hello'))
def first():
print("first")
def second():
print("second")
f = first
s = second
def y(l):
l()
y(f)
#first
y(s)
#second
def perform(fun, *args):
fun(*args)
def action1(args):
# something
def action2(args):
# something
perform(action1)
perform(action2, p)
perform(action3, p, r)