June 2017
Beginner
352 pages
8h 39m
English
When you supply a default parameter value for a function, you do so by providing an expression. This expression can be a simple literal value, or it can be a more complex function call. In order to actually use the default value that you provide, Python has to at some point evaluate that expression.
It's crucial, then, to have an appreciation of exactly when Python evaluates the default value expression. This will help you to avoid a common pitfall which frequently ensnares newcomers to Python. Let's examine this question closely using the Python standard library time module:
>>> import time
We can easily get the current time as a readable string by using the ctime() function of the time module:
>>> time.ctime() ...
Read now
Unlock full access