shell
, print
, and ipdb
global
keywordtry:
and except:
Who: Guido van Rossum
When: February 20, 1991
Eponym: Monty Python’s Flying Circus
Began as a personal project based on another language he wrote called ABC with the intention of making it easier to read and program in C.
Python is an experiment in how much freedom programmers need. Too much freedom and nobody can read another’s code; too little and expressiveness is endangered.
-Guido van Rossum
Let's install a popular package for sending HTTP requests
pip install requests
To install a specific version:
pip install requests==2.22.0
To uninstall a package:
pip uninstall requests
When deploying, you will use pip to create a requirements file:
pip install -r requirements.txt
python
at the command line.exit()
or ctrl + d
Example | Data Type | Name |
---|---|---|
"Hello Python" |
str | string |
20 |
int | integer |
20.5 |
float | float |
[1, 2, 3] |
list | list |
(1, 2, 3) |
tuple | tuple |
{"name": "Mimi", "age": 10} |
dict | dictionary |
{2, 4, 6} |
set | set |
True |
bool | boolean |
None |
NoneType | NoneType |
Pyenv is the tool we’ll use to install and manage different versions of Python.
pyenv versions
will show you what Python versions are currently installed on your machinepyenv install -l
will show a list of versions available to installpyenv install 3.9.2
will install that version on your machinepyenv global 3.9.2
will set that as the global version on your machinePipenv is a tool built upon pip
which can create virtual environments and install packages in them.
Pipfile
: look for this first, it is analogous to npm’s package.json file and lists the dependencies and Python version for the current projectPipfile.lock
: similar to package-lock.json, this file describes both the Pipfile dependencies AND their dependencies with exact versionsIf the project directory doesn’t have these, you need to create a virtual environment
pipenv --python 3.8.13
Now you can start adding dependencies similarly to how you would install packages with pip
:
pipenv install requests
Command | Description |
---|---|
pipenv install |
creates the virtual environment and installs dependencies |
pipenv shell |
activates the virtual environment |
ctrl + d |
deactivates the virtual environment |
pipenv --rm |
removes the virtual environment |