4. Functions
Objectives
In this chapter, you’ll
Create custom functions.
Import and use Python Standard Library modules, such as
randomandmath, to reuse code and avoid “reinventing the wheel.”Pass data between functions.
Generate a range of random numbers.
See simulation techniques using random-number generation.
Seed the random number generator to ensure reproducibility.
Pack values into a tuple and unpack values from a tuple.
Return multiple values from a function via a tuple.
Understand how an identifier’s scope determines where in your program you can use it.
Create functions with default parameter values.
Call functions with keyword arguments.
Create functions that can receive any number of arguments.
Use methods of an object.
Write ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access