Lesson 35. Useful libraries

 

After reading lesson 35, you’ll be able to

  • Bring libraries from outside the standard Python package into your code
  • Use the math library to do mathematical operations
  • Use the random library to generate random numbers
  • Use the time library to time programs

Programming is an activity that’s usually most efficient and enjoyable when you build upon work that others have done. Some problems have already been solved, and code has likely been written to solve similar tasks to the ones that you’re trying to solve. It’s highly unlikely that you’ll have to start a task by implementing code to do everything from scratch. In any language, libraries exist that you can use to help you code tasks in a modular way: by building upon code that’s already written, tested, and debugged for correctness and efficiency.

To some extent, you’ve already been doing this! You’ve been using objects and operations built into the Python language. Imagine how tough learning to program would’ve been if you had to learn how to work with memory locations in the computer and to build up everything from scratch.

35.1. Importing libraries

 
 
 
 

35.2. Doing mathematical operations with the math library

 
 
 
 

35.3. Random numbers with the random library

 
 
 
 

35.4. Timing programs with the time library

 
 
 
 

Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage