Week 4 Libraries - CS50's Introduction to Programming with Python
- Generally, libraries are bits of code written by you or others can you can use in your program.
- Python allows you to share functions or features with others as “modules”.
- If you copy and paste code from an old project, chances are you can create such a module or library that you could bring into your new project.
random
is a library that comes with Python that you could import into your own project.
- It’s easier as a coder to stand on the shoulders of prior coders.
- So, how do you load a module into your own program? You can use the word
import
in your program.
- Inside the
random
module, there is a built-in function called random.choice(seq)
. random
is the module you are importing. Inside that module, there is the choice
function. That function takes into it a seq
or sequence that is a list.