Please ask any questions at any time!
Click here to go to the download page
Add Miniforge to PATH when prompted during installation.
Try the below in either your terminal (Mac/Linux) or Miniconda Prompt (Windows):
Windows troubleshooting
conda not found? Run conda init in your terminal.gitPopularity
Free and open source
Versatile Not just for data analysis / machine learning
Packages for everything!
 Numpy: arrays
 Pandas: dataframes
 SciPy: scientific computing
 Scikit-image: image analysis
 PyTorch: machine learning
 Matplotlib: plotting
People have spent lots of time optimising these packages! Don’t reinvent the wheel!
-- or - (double or single dash)-h, --help or man <command>Ctrl+C or Ctrl+ZTab key to autocomplete commands and file namesUp and Down keys to cycle through command historyq (typically) to quit multi-page outputspython is a program that can be run from the terminalREPL (Read-Eval-Print Loop), “interactive Python”, “Python console”Jupyter notebooks (.ipynb)Scripts (.py)Demo time! 🧑🏻💻👩🏻💻

The value of a is:
1
The value of c is:
3
The value of a is now:
2
The value of x is:
10
The value of y is:
20
type() function to find out what type of data a variable contains<class 'str'>
I want to learn Python!
a*3 in the code abovef before the string{variable} to insert variables into the stringYou can also use f-strings to format numbers
100'Dog'3.14printFalse'50'None[][]my_list?3.0?my_list[5]?()my_list into a tuple?my_tuple into a list?{}dict_keys(['a_number', 'number_list', 'a_string', 5.0])
dict_values([1, [1, 2, 3], 'string', 'a float key'])
dict_items([('a_number', 1), ('number_list', [1, 2, 3]), ('a_string', 'string'), (5.0, 'a float key')])
string
a float key
% and == to check for evennessand and or_ if you don’t need the loop variableenumerate() gives you the index and the valuerange() generates a sequence of numbers
range(n) from 0 to n-1range(a, b) from a to b-1range(a, b, step) from a to b-1 with jumps of stepMy pet is a: cat
My pet is a: dog
My pet is a: rabbit
55
while!Not there yet...
Result is 0
Not there yet...
Result is 1
Not there yet...
Result is 2
Not there yet...
Result is 3
Not there yet...
Result is 4
Not there yet...
Result is 5
Not there yet...
Result is 6
Not there yet...
Result is 7
Not there yet...
Result is 8
Not there yet...
Result is 9
We got there!
[expression for item in iterable][expression for item in iterable if condition]REPL (Read-Eval-Print Loop), “interactive Python”, “Python console”Jupyter notebooks (.ipynb)Scripts (.py)Demo time! 🧑🏻💻👩🏻💻

with to do this automaticallydef keywordTrue if the password is long enough, and False otherwiselen() function to get the length of a stringTrue
False
name=valueFirst animal: dog
Second animal: cat
Third animal: penguin
First animal: cow
Second animal: elephant
Third animal: penguin
Cell In[63], line 1 def list_animals(first="dog", second, third="penguin"): ^ SyntaxError: parameter without a default follows parameter with a default
banana
apple
* and *** and ** are upacking operators, useful to unpack tuples, lists and dictionaries*args and **kwargs beforeUnpacking positional arguments: (1, 2, 3, 4, 5)
Unpacking keyword arguments: {}
Unpacking positional arguments: ()
Unpacking keyword arguments: {'a': 1, 'b': 2, 'c': 3}
* and **Unpacking positional arguments: (1, 'a', 3.14)
Unpacking keyword arguments: {}
Unpacking positional arguments: ()
Unpacking keyword arguments: {'name': 'John', 'age': 30}
Unpacking positional arguments: (1, 2, 3)
Unpacking keyword arguments: {'name': 'Jane', 'city': 'New York'}
*args and **kwargs useful?*args and **kwargs are useful when you don’t know which arguments will be passed to the functionreturn keywordNoneclass keyword__init__ method is called when an object is createdself refers to the instance of the classnoise to the Animal classmake_noise that prints the noise of the animalnoot
--------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) Cell In[81], line 1 ----> 1 import london ModuleNotFoundError: No module named 'london'
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[82], line 1 ----> 1 len(print) TypeError: object of type 'builtin_function_or_method' has no len()
Cell In[84], line 1 print hello ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
--------------------------------------------------------------------------- ZeroDivisionError Traceback (most recent call last) Cell In[87], line 1 ----> 1 1 / 0 ZeroDivisionError: division by zero
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[88], line 1 ----> 1 giraffe * 10 NameError: name 'giraffe' is not defined
--------------------------------------------------------------------------- ZeroDivisionError Traceback (most recent call last) Cell In[90], line 7 4 def call_func(x): 5 y = divide_0(x) ----> 7 z = call_func(10) Cell In[90], line 5, in call_func(x) 4 def call_func(x): ----> 5 y = divide_0(x) Cell In[90], line 2, in divide_0(x) 1 def divide_0(x): ----> 2 return x / 0 ZeroDivisionError: division by zero
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[91], line 8 5 return none_function() 7 file_name = none_function() ----> 8 open_file = open(file_name) File ~/.local/lib/python3.12/site-packages/IPython/core/interactiveshell.py:343, in _modified_open(file, *args, **kwargs) 336 if file in {0, 1, 2}: 337 raise ValueError( 338 f"IPython won't let you open fd={file} by default " 339 "as it is likely to crash IPython. If you know what you are doing, " 340 "you can use builtins' open." 341 ) --> 343 return io_open(file, *args, **kwargs) TypeError: expected str, bytes or os.PathLike object, not NoneType
5.0
--------------------------------------------------------------------------- ZeroDivisionError Traceback (most recent call last) Cell In[92], line 5 2 print(x / y) # This might raise an error 4 divide(10, 2) ----> 5 divide(10, 0) Cell In[92], line 2, in divide(x, y) 1 def divide(x, y): ----> 2 print(x / y) ZeroDivisionError: division by zero
try and exceptexcept too general!Result: 5.0
Y cannot be zero!
Both x and y must be numbers!
None5
None
3
You can click on the name to go to the download page.
Install the one you like most!
Igor prefers PyCharm, Laura prefers VS Code.
package manager and virtual environment managerIn your terminal (use Anaconda Prompt on Windows):
python-introIn your terminal (use Anaconda Prompt on Windows):
In your terminal (use Anaconda Prompt on Windows):
In your terminal (use Anaconda Prompt on Windows):
In your terminal (use Anaconda Prompt on Windows):
python-intro environment and all its packagesimport and from keywordsImportant
from ... import ...as
pandas is pdIn your conda environment, using pip:
numpynumpynumpy version 1.26.4numpymatplotlib and scikit-image in one commandpip listanalysis.py, import the functions from my_funcs.py and use them""" for docstringsREADME.md or README.txtwhich python or which pip to checkin_place or not
pandas and numpypyproject.toml → more on this in future sessions!pdb, or IDE built-in debuggers)pytest)
Comments
#for single-line comments"""for multi-line comments or docstrings