-
What is Code?
-
Data
-
Input
-
Functions
-
Boolean logic and decisions
-
Loops
-
Modules
-
Examples
-
Exercises
Import
Python has a lot of instructions for us to use. They are part of the language and can be used by everyone.
print
is a good example of this.
Sometimes people create useful code that can be shared and used by other people.
Code that is created for a purpose like this is called a module
or library
.
A good example for us is the random
module.
When we use the import
instruction to import a module, we can then use functions from that module.
In this example random
is a module full of useful functions related to random numbers.
One of the functions is randint(from, to)
which returns a random number between the numbers from
and to
.
Try running this code a few times to see the different results.
Here's another example, which could be useful.