Coding Curriculum - Python

Importing Functions

But before we think about that, let's first have a look at a random number generator in Python. We will use 2 different functions to get a random result back and they can both be found in, you guessed it, the random library.

Hence, before we can access those functions we first need to import them. Here we have 2 choices:

We import the entire library

import random

We only import the 2 functions we need

from random import randint, choice

Which one do you think is the best? That's right! The less functions you import, the easier your life will be!

So in order to import the functions that we will need, we will use the second option. So this is what our code looks like right now:

from random import randint, choice