{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7618b1bf",
   "metadata": {},
   "source": [
    "(content:appendix:a)=\n",
    "# A. Python primer"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "75edd7f3",
   "metadata": {},
   "source": [
    "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The aim of this primer is to provide an introduction to Python’s computational capabilities. This primer is not intended to be a general introduction to computer programming, but a basic introduction to understand the code examples in this book, geared toward novice Python users. Readers already skilled at programming in Python will probably choose to skip this appendix, although some parts may be useful as a refresher."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "04d92297",
   "metadata": {},
   "source": [
    "## About Python\n",
    "\n",
    "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Python is an open-source, object-oriented programming language used for both standalone programs and scripting applications. It was initially developed by Guido van Rossum, who named it after Monty Python’s Flying Circus. Over the past decades, Python has become extremely popular as a programming language in science and engineering. This is not only because it is one of the easiest programming languages to learn, but also because it has many extensions that make Python a programming language that can be used for an enormous range of applications. Other advantages are that it is open source and runs on all major operating systems.\n",
    "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Python consists of the core language and comes with a comprehensive standard library. In addition, there are many third-party packages (or libraries) for tasks that are not included in the standard library. Both Python and third-party packages are being developed and updated regularly. The code in this book was orignally written in Python 3.8, and has been tested up to Python 3.13, but it is expected that most, if not all, examples will work with even newer versions.\n",
    "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Python is an interpreted language, which means that it is not necessary to compile it into binary machine code before a program can be run. Instead, the commands are typed (or read from a script) in an interpreter, which may be embedded in a web browser, as is the case when using Jupyter Notebooks."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "161346ff",
   "metadata": {
    "jp-MarkdownHeadingCollapsed": true
   },
   "source": [
    "## Installation\n",
    "\n",
    "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Users who want to run the code examples in this book on their own computer must first install Python and all the required extensions and tools. It is recommened to use either a program to facilitate management of Python packages or to install a so-called Python distribution, which includes Python and a whole suite of extensions that are pre-packaged into a single installer. \n",
    "\n",
    "Miniforge is a lightweight, open-source installer for Python to facilitate easy installation and management of Python packages. Download Python from [miniforge](https://conda-forge.org/download/). If you are installing on Windows, follow the installation instructions. On macOS or Linux, open a terminal and run the (somewhat cryptic, if you are not used to Unix) command `bash Miniforge3-$(uname)-$(uname -m).sh`.  \n",
    "\n",
    "To run the code examples in this book, the `numpy`, `matplotlib`, and `scipy` packages are needed; all these packages are discussed in this appendix. Here, the `pip` command is used to install packages (pip stands for Package Installer for Python). Open the \"Miniforge Prompt\" from the Start menu (Windows). On macOS or Linux, open a terminal. At the prompt, type `pip install numpy matplotlib scipy` and press the enter/return button, after which these packages will be installed. \n",
    "\n",
    "Jupyter notebooks can be opened from several different applications, for example from Jupyter Lab (they can’t be opened by double-clicking on them). New notebooks can also be created in Jupyter Lab. To install Jupyter Lab, type `pip install jupyterlab` at the Miniforge prompt (or terminal) and press the enter/return button. After installation is complete, Jupyter Lab can be started by typing `jupyter lab` at the Miniforge prompt (or terminal) and pressing enter/return. This will open Jupyter Lab in your default webbrowser. The left side of Jupyter Lab is a file browser. Jupyter Notebooks (and many other file types) can be opened by double-clicking on them.  It can happen that the Jupyter Notebook to be opened is not accessible using Jupyter Lab’s file browser (for example when the file is on a different drive than the one visible to the file browser). In that case, change the active working directory at the Miniforge prompt (or terminal) before typing `jupyter lab`."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f2f825ff",
   "metadata": {},
   "source": [
    "## Jupyter Notebooks\n",
    "\n",
    "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Jupyter Notebooks (or simply “notebooks”) provide a way to execute Python code in a web browser. A notebook consists of cells, which either have text or code. The code cells can easily be recognized as they are preceded by `[ ]:` or `[n]:` where `n` is a counter. To see what a code fragment does, position your cursor in one of the code cells of a notebook (either by clicking the left mouse button or by navigating using the up and down arrow keys), hold the [shift] key, and hit [enter] or click the Run button. The output (if any) will appear below the code cell and will also be preceded by `[n]:` (where `n` is the same number as the code cell).\n",
    "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Each time one of the code cells in a notebook gets executed, `n` gets increased by 1. This means that if code cells are executed one by one starting from the top, they will be numbered successively from top to bottom. But if cells are not executed in a systematic way, which may happen when a user is experimenting with the code examples, the numbering may differ. More often than not, a user does not have to worry about the numbering, but if there are any problems with the code, it may help to remember that the last cell that was executed has the highest number `n`.\n",
    "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; It is possible to change the code cells to play around with the examples, but note that some examples later on in a notebook may not work as intended anymore. If a code cell behaves unexpectedly, it may be because something was defined erroneously in one of the cells above it. To help locate the problem, clear all the code output from the notebook by selecting `Kernel` → `Restart Kernel and Clear Outputs of All Cells` from the menu and start executing again from the top."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
