预计阅读本页时间:-
Definition
Here’s a definition typed interactively that defines a function called times, which returns the product of its two arguments:
>>> def times(x, y): # Create and assign function
... return x * y # Body executed when called
...
广告:个人专属 VPN,独立 IP,无限流量,多机房切换,还可以屏蔽广告和恶意软件,每月最低仅 5 美元
When Python reaches and runs this def, it creates a new function object that packages the function’s code and assigns the object to the name times. Typically, such a statement is coded in a module file and runs when the enclosing file is imported; for something this small, though, the interactive prompt suffices.