Section 3.7 Introduction to Python Modules
One of the best things about the Python programming language is the ecosystem that surrounds it. This chapter introduces you to how to import and use modules that other people have created. Youβll learn about how to use the random module which comes in handy quite frequently in programming. This chapter also does a deeper dive into the turtle module which isnβt often used to solve real-world problems, but is a useful and fun module to use when learning how to program.
Source: https://imgs.xkcd.com/comics/python.png
β1β
https://imgs.xkcd.com/comics/python.png
Python provides us the ability to use modules to do everything from sending emails to image processing to complex machine learning. But, even though Python gives us a tremendous amount of power from these modules, you still need to know the Python basics in order to glue everything together. We will start by looking at a module used to generate random numbers to learn how to make use of other modules in your programs.
Subsection 3.7.1 Learning Goals
- Understand that Python is extensible through modules
- Understand how to use modules
- Understand the usefulness of random numbers in programming
- Learn more about using the turtle module
Subsection 3.7.2 Objectives
- To import an entire module
- To import a single function from a module
- To import a module giving it an alias
- To learn how to use random.random() and random.randrange() to get random floats and ints
- To learn how to use random.choice() to get random elements from a list
You have attempted of activities on this page.