26/May/2016:

** Hey, what's this 'functools' thingy, huh !?!


In [9]:
import functools

def hello_doctor(greet_msg, greet_whom):
    return "%s %s, Welcome to the world of robots." %(greet_msg, greet_whom)

## this line works
# hello_doctor = functools.partial(hello_doctor, "R2-D2")
# hello_doctor("Dr.Susan Calvin")


Out[9]:
'R2-D2 Dr.Susan Calvin, Welcome to the world of robots.'
What's going on in cells 11 & 14 ?

In [11]:
greet = functools.partial(hello_doctor)
greet("Dr.Susan Calvin")


Out[11]:
'R2-D2 Dr.Susan Calvin, Welcome to the world of robots.'

In [14]:
welcome = functools.partial(hello_doctor)
welcome("Dr.Susan Calvin")


Out[14]:
'R2-D2 Dr.Susan Calvin, Welcome to the world of robots.'

In [4]:
def numpower(base, exponent):
    return base ** exponent

def square(base):
    return numpower(base, 2)

def cube(base):
    return numpower(base, 3)
    
print square(25)
print cube(15)


625
3375

How can the above code be handled using functools.partial() ?