Lecture 4 - Libraries +
Lecture 4 - Libraries +
Libraries are generally files of code that other people have written that you can use
your own program,
or a library code that you have written that you can use in your own program
1. Modules +
Module in Python is just a library that typically has one or more functions or other
features built into it
There is a file called random.py that is written by someone, and we can access to the
functions inside the random.py file
2. Import +
Import keyword allows us to import the contents of functions from some module in
Python
3. From +
From allows us to import functions from a module, but it is more specific
“Import random” means that we are accessing all of the functions in random library
4. Statistics (Built-in)
5. Command-line Arguments, sys
Sys
Sys.argv, it stands for argument vector, it means the variables in the command-line
interface
7. Slice
Problem
8. Packages +
PyPI
To use the package, we need to figure it out how to download, unzip and put it
somewhere
But in Python, we use package manager, pip, pip is a program that generally comes
with Python, that allows us to install packages on our PC
9. Cowsay
10. API, requests, JSON
We can pretend a browser and connect to that third-party API on server, and download
some data that you can incorporate in the program
When Python has read the file from top to bottom, the last line of code is to call
“main”. Main is called no mater what
__name__, it is a special variable set by Python to “main” when you run a file from
command line
When we run the program in command line, Python will automatically set __name__
to “__main__”