Save
prograhams
Save
Share
Learn
Content
Leaderboard
Learn
Created by
MinorAngonoka25843
Visit profile
Cards (25)
Libraries
Bits
of code written by you or others that you
can use in your program
Modules
Python allows you to share
functions
or
features
with others
If you
copy and paste code from an old project
, you can create a
module or library to bring into your new project
Random library
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
Importing a module
Use the word
import
in your program
random.choice
(seq)
A function in the random module that takes a
sequence
(list) and
randomly
selects an item from it
Sequence passed to
random.choice
()
List with square
brackets
,
quotes
, and commas
Passing two items to
random.choice
()
Python gives a
50
% chance for each item
Importing specific
functions
from a
module
Use the
from
keyword to explicitly import only the
functions
you need
random.randint(a, b)
A function in the
random
module that generates a random integer
between
a and b
Statistics
library
A built-in Python library with useful
statistical
functions like
mean()
Accessing command-line
arguments
Use the
sys
module and sys.argv to get the
arguments
the user typed at the command line
sys.argv[0] contains the
name
of the Python
script
Handling missing command-line arguments
Use
try-except blocks
to catch and handle errors when the user doesn't provide the
expected
arguments
Exiting the program on
error
Use
sys.exit
() to exit the program cleanly when an
error
is encountered
Slice
A way to take a
subset
of a list by specifying the
start
and end indices
Python lists are
zero-indexed
, so the first element is at index
0
Packages
Third-party libraries
implemented as a folder, that add
functionality
to Python
PyPI
is a repository of all available
third-party
Python packages
Pip
Python's package manager that allows you to install
packages
quickly
APIs
Application Programming Interfaces
that allow your program to
connect
to and use the code of others
The
iTunes
API provides a
JSON-formatted
data feed that you can access in your Python programs
Creating your own
library
Write
functions
in a Python file that can be
imported
and used by other programs
You can create your own libraries to
reuse
code or share with others