Giving another name to a function

After you import a function, you can give it a new name. The additional name refers to the same object at the same location as the old name, as this example shows:

>>> tinyfunction

<function tinyfunction at 0x61430> >>> myfunc = tinyfunction

>>> myfunc function tinyfunction at 0x61430>

Tip It's important to remember the difference between giving a new name to a function and calling a function while giving a name to the result. When you call a function, you add parentheses at the end of the function name. These examples show the difference:

>>> myfunction = tinymodule.tinyfunction # giving a new name to a function

>>> myresult = tinymodule.tinyfunction(2) # calling a function

Was this article helpful?

0 0

Post a comment