<jupyter_start><jupyter_text>The JupyterLab InterfaceThe JupyterLab interface consists of a main work area containing tabs of documents and activities, a collapsible left sidebar, and a menu bar. The left sidebar contains a file browser, the list of running terminals and kernels, the table of contents, and the extension manager.![jupyter_lab_startup_page](figures/jupyter_lab_startup.png)JupyterLab sessions always reside in a workspace. Workspaces contain the state of JupyterLab: the files that are currently open, the layout of the application areas and tabs, etc.Reference: [https://jupyterlab.readthedocs.io/en/latest/user/interface.html](https://jupyterlab.readthedocs.io/en/latest/user/interface.html)  NotebookCurrently you are looking at a Jupyter Notebook. A Jupyter Notebook is an interactive environment for writing and running ocde. The notebook is capable of running code in a wide range of languages. However, each notebook is associated with a single kernel. This notebook is associated with the IPython kernel, therefore it runs Python code.Reference: [https://github.com/jupyter/notebook/blob/6.1.x/docs/source/examples/Notebook/Running%20Code.ipynb](https://github.com/jupyter/notebook/blob/6.1.x/docs/source/examples/Notebook/Running%20Code.ipynb)  Notebook Cell TypesIn a Jupyter Notebook we can have text cells and code cells. In text cells we can write markdown ([Markdown cheat sheet](https://www.markdownguide.org/cheat-sheet/)).In code cells we can write program code which is executed by the IPython kernel associated with the notebook.Code cells have brackets `[ ]:` in front of them:* `[ ]:` means that the cell is empty.* `[*]:` means that the cell is currently being executed.* `[1]:` here the number indicates the execution step in the notebook. This execution step is updated everytime the cell is executed.To render a text cell or execute a code cell you can press the run button in the toolbar above or press `Shift-Enter` on your keyboard.<jupyter_code>2 + 2
# If we want to write text in a code cell we have to comment it out with '#'.

# Next we asign some variables.
a = 2
b = 2
c = a + b
print("a is", a)
print("b is", b)
print("a + b =", c)<jupyter_output><empty_output><jupyter_text>Displaying an Image<jupyter_code># import packages
from tifffile import imread
from matplotlib import pyplot as plt
img = imread('imgs/t000.tif')
plt.figure(figsize=(10, 10))
plt.imshow(img, cmap='gray')<jupyter_output><empty_output><jupyter_text>Python Basics  If StatementThe if statement allows us to branch code and act on different conditions.The statement has the following logic:```if condition_0:    code_0elif condition_1:    code_1else:    code_2````code_0` is executed if `condition_0` holds true. If `condition_0` is false `condition_1` is evaluated and `code_1` is executed if `condition_1` is true. If both conditions evaluate to false `code_2` is executed. __Note:__ `elif` and `else` are optional.<jupyter_code># Assign value to number
number = 3

# Test if the number is negative, zero or positive
if number < 0:
    print("{} is a negative number.".format(number))
elif number == 0:
    print("The number is zero.")
else:
    print("{} is a positive number.".format(number))

# The following code is outside of the if statement and always executed.
print("Done")<jupyter_output><empty_output><jupyter_text>FunctionsIn Python we can define functions which can be reused in our code. It is good practice to define a function if we want to reuse the same code multiple times!<jupyter_code>def categorize_number(number):
    """
    Prints to standard output if the number is negative, zero or positive.
    
    Parameter:
    ----------
    number: The number to categorize.
    """
    if number < 0:
        print("{} is a negative number.".format(number))
    elif number == 0:
        print("The number is zero.")
    else:
        print("{} is a positive number.".format(number))
categorize_number(number=-2)<jupyter_output><empty_output><jupyter_text>ListsIn python we can easily define a list.<jupyter_code>numbers = [-1, 0, 1, 2]
type(numbers)<jupyter_output><empty_output><jupyter_text>For LoopIf we want to apply some code (e.g. a function) to all elements of a list we can use a for loop.<jupyter_code>for number in numbers:
    print("Currently processing number = {}.".format(number))
    categorize_number(number)<jupyter_output><empty_output><jupyter_text>RangeA typical usecase is that we want to get all numbers from 0 up to a given number e.g. 100. Luckely we don't have to type all 100 numbers into a list to iterate over them. We can just use the `range`-function which is part of Python.<jupyter_code>for i in range(100):
    categorize_number(number=i)
import this<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0901449884429502, 'fraction_numerical': 0.010926665265812145, 'mean_word_length': 4.734939759036145, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 29, 'https://': 5, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '8260', 'license': 'MIT', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1394, 'n_words': 574, 'path': '00-python-setup/Getting Started.ipynb', 'repo_name': 'fmi-faim/py_course', 'size': '4759'}