Simple Function Question

Akira Kiyomiya akira.kiyomiya at autodesk.com
Wed Apr 26 14:44:45 EDT 2000


Hi,  Could you explain this in dummy's language?

This function prints out '4' and I have a feeling that x=1 and n=3, so
add1(3) prints '4'.

However, I have a difficlut time trying to see how these two arguments
assigned to both x (especially x) and n.

Thanks

Akira


# Return a function that returns its argument incremented by 'n'
def make_incrementer(n):
    def increment(x, n=n):
        return x+n
    return increment

add1 = make_incrementer(1)
print add1(3)  # This prints '4'








More information about the Python-list mailing list