Welcome to Python Basics, a structured introduction to Python programming. This course covers fundamental concepts, data structures, functions, and essential libraries like NumPy and Matplotlib. Through hands-on exercises, you'll build a solid foundation for practical programming.
About this Course
This course was developed at the Institute for Neuromodulation and Neurotechnology at the University and University Hospital Tuebingen, Germany. We have used similar notebooks to teach undegraduates for data analysis in our course "Neuromodulation and Neuroplasticity". We have adapted the materials to be for a more general audience, but applications and exercise of course still show its neuroscientific origins.
We intend to include more recap sessions and exercises in the future!
Course Authors
Joshua P. Woller, M.Sc. (@syntheticdinosaur)
David Menrath, M.Sc. (@DavidMenrath)
To use Jupyter Notebooks, you typically need Python installed on your computer. However, to make it easier to get started without any setup, you can run the notebooks directly in your web browser using online services. This allows you to start coding right away without installing anything.
Below, we present different ways to run the notebooks. Choose the option that best fits your needs.
Here you can find more information on Jupyter Notebooks.
Binder lets you run Jupyter Notebooks directly in your web browser without installing anything. This is the easiest way to get started quickly. However, Binder does not save your changes permanently, so if you modify the notebooks, you need to download your work manually before closing the session.
Click below to launch the course in Binder:
Google Colab is a free cloud-based notebook service provided by Google. It allows you to run Jupyter Notebooks without any installation. One key advantage is that Colab automatically saves your work in Google Drive, making it easy to continue where you left off. However, you will need a Google account to use it, and some advanced Python libraries may require additional setup.
Click below to open the course in Google Colab:
GitHub Codespaces allows you to run the notebooks in a full VS Code environment in your browser. This option provides a more powerful development environment and automatically saves your work, but it requires a GitHub account and may have resource limitations on free accounts.
Click below to launch the course in GitHub Codespaces:
If you already have Python installed on your computer, you can download the notebooks and run them locally. This allows you to work in your own environment with full control over your files and installed libraries. You can either download the repository as a ZIP file and extract it. If you are familiar with GitHub, you can also clone the repository using Git to keep it organized on your machine. If you prefer to keep your own version and track changes, you can fork the repository on GitHub and work with it independently. Running the notebooks locally requires Python and Jupyter Notebook to be set up on your system.
-
Core Python – Variables, data types, lists, and control flow
-
Introduction to Python Programming
Overview of programming, variables, and the first steps in Python using a "Hello World" program. -
Python as a Calculator
Perform basic math operations, and equality testing. -
Using Variables
Learn how to create, assign, and update variables in Python. -
Variable Types
Introduction to different variable types in Python (e.g., int, str, float, bool) and how to determine and work with them. -
List Basics
Introduction to creating and manipulating lists in Python, including indexing and slicing. -
Further List Operations
Learn about merging and combining lists, removing and replacing elements from lists. -
Sets and Dictionaries
Introduction to other iterables such as sets and dictionaries, and their differences to lists. -
Logical Operations
Introduces boolean or logical values, as well as logical operators such as 'and', 'or', 'xor', and 'not'. -
Control Flow
Shows conditional code execution in if-elif-else statements, and for-loops as well as while-loops.
-
-
Functions & Advanced Concepts – Functions, classes, and modules
-
Functions: Basics
How to create and call basic functions, and how to use return statements in functions. -
Functions: Advanced
Using default arguments in functions, cautionary notes on variable scope and an introduction to documenting your code using docstrings. -
Mutability
We discuss mutable and immutable datatypes, how to test for the identity of objects, and consequences of passing mutable objects between caller and function. -
Classes and Objects
Introduces the concept of classes, and how to create objects. Also provides a glimpse at .set() and .get() methods to safely extract or modify class attributes. -
Modules
Teaches how to import (and install) external modules, how to use their functions, and how to use aliases for modules. -
Dataclasses: Basics
Shows the concept of dataclasses, which are a compact way to represent linked data using specific objects. -
Dataclasses: Fields
Introduces the concept of fields, which prevents multiple instances of a class from sharing ownership of the same mutable object if such behavior is not desired.
-
-
NumPy – Efficient numerical computing
-
Introduction to NumPy
In this notebook, we show how to import NumPy and how to create a basic NumPy array from an existing Python list. -
NumPy Array Types
Introduces various datatypes an array can hold, and the concept that a NumPy array casts all contained elements to a single shared type. -
Array Shapes
Discusses shapes, and their influence on combining arrays, e.g. by arithmetic operations. We also discuss how to change the shape of arrays to make them compatible. -
Mutability
We discuss the concept of views vs copies in NumPy, how that relates to the concept of mutability we learned before, and the practical implications thereof. -
Numerical Operations
An overview of numerical operations between different arrays, or summary operations such as taking the mean, on individual arrays. Showcase for a lot of the potential operations supported by NumPy. -
Array Manipulations
How to combine and extend arrays. -
Efficiency
A short introduction showing computational advantages of NumPy arrays.
-
-
Matplotlib – Data visualization basics
-
Introduction to Matplotlib
This notebook provides an introduction to matplot, shows how to create and adapt simple plots, and showcases the different types of plots the library has to offer. -
Styling and Export
In this notebook, we discuss ways to individualize plots and to prepare them for export in various file formats.
-