Chapter 3Roll the Dice

Image

Now that you know how to use functions and variables, we’re going to make things more interesting by introducing libraries and a whole lot of randomness.

Using Libraries

We briefly mentioned libraries back in Chapter 1. You can think of libraries as collections of code—usually functions (like the print() and input() functions you’ve already used). Libraries are easy to use. You just tell Python what library you need, and you get to use the functions in it. Simple as that. Yes, someone else did the hard work, and you get to just use it. Nice, huh?

Python comes with lots of libraries included. There is one called datetime ...

Get Captain Code: Unleash Your Coding Superpower with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.