<jupyter_start><jupyter_text>Introduction 1) What is Python?Python was ceated in 1989 by <NAME>, in Netherland. The name is a tribute to the `Monty Python’s Flying Circus` TV show. The first version of Python dates from 1991.Python 2.7 was released on July 3rd 2010, and will not be supported anymore from January 2020. Python 3.7 was release on June 20th 2018 and will be supported in the future, which is the reason why we are using it. 2) Why using Python?There are many reason to use this language:- It is cross-platform, and works on many OS, or hardware.- It is free.- It is a high level language, and do not necessitate a lot of knowledge on computers.- It is interpreted, it does not need to be compiled.- It is oriented object.- It is easy to start with.- It is the language currently used in the industry and academia for data analysis. 3) Some exemple why Python is easy to use: Quicksort Pseudocode from Wikipedia<jupyter_code>function quicksort(array)
    var list less, greater
    if 
    length(array) ≤ 1
        return array
    select and remove a pivot value pivot from array
    for each x in array
        if x ≤ pivot then append x to less
        else append x to greater
    return concatenate(quicksort(less), pivot, quicksort(greater))<jupyter_output><empty_output><jupyter_text>Here is a Python implementation<jupyter_code>import random

# A python implementation of the Wikipedia quicksort algorithm
def my_quicksort(array):
    if len(array) <= 1:
        return array
    
    pivot = array[0] # select a pivot (first element of list)
    rest = array[1:] # the array with the pivot
                     # removed
    less = [x for x in rest if x <= pivot]
    greater = [x for x in rest if x > pivot]
    
    return my_quicksort(less) + [pivot] + my_quicksort(greater)

testarr = [random.randint(-1000, 1000) for i in range(30)]
print(testarr)
print(my_quicksort(testarr))<jupyter_output><empty_output><jupyter_text>As you can see the implementation is easy to read, although you will know more about each instructions at the end of this tutorial!As we said before we will use the jupyter notebook in this tutorial so let's take a look at that in further details:  4)  Jupyter NotebookJupyter Notebook allow to run different type of language, including Python3. The main advantage is that everything, comments, code, image,... is integrated in the web browser. 4.1) First steps:We have already seen how to start a Notebook session. In order to start a new Notebook, just do: ``File -> New Notebook``. Make sure that the document is started in Python3. When starting a new notebook the first thing we see is a cell, inside which we can enter anything:<jupyter_code>print("Hello World!")<jupyter_output><empty_output><jupyter_text>And run it using the ``Run`` bouton. The cell can be modified and reexectued as many times as we want.   4.2) Markdown cells:One can modify the type of the cell using the scroll down menu where ``Code`` is by marked by default. The ``Markdown`` menu can be used to write down text, tables, and display picture. The current cell you are reading is a Markdown cell.There many things that can be used in such a cell:- Title: Obtains using "" characters (1-4).- Latex: Use the latex formatting with character: "$".- There are many other markdown codes that can be found, for instance at:https://www.ibm.com/support/knowledgecenter/en/SSGNPV_1.1.3/dsx/markd-jupyter.html  4.3) Running linux commands:This is obtained by adding a "!" char in front of the linux command. For instance:<jupyter_code># list current directories contents
!ls -F
# print working dirctory
!pwd
# change directoty; NOTE: to change the directory for the IPython
# session, you need to prepend 'cd' with a percent sign (jupyter magic)
%cd data
!ls
%cd ..<jupyter_output><empty_output><jupyter_text>4.4) Run and examine script-code from disk or the web:<jupyter_code># The notebook offers 'magic'-commands
# Python-code is here in a code-subdiretory
%run ./python/magic_test.py
%load python/magic_test.py
# list variables currently defined within this notebook.
# Here we see variables that were originally defined in the program
# code/magic_test.py
%whos
%load https://matplotlib.org/mpl_examples/lines_bars_and_markers/line_demo_dash_control.py<jupyter_output><empty_output><jupyter_text>4.5) Find available methods and functions within modules and objects<jupyter_code># You can search for function-names
import numpy

# You want to find out, how the numpy-function for arcus-cosinus is. You know that
# the function name certainly has cos in it:
numpy.*cos*?
# list all numpy commands ending with sin
#numpy.*sin?
# You can search for 'methods' (functions) that can be applied to objects:
s = "Hello world"
print(s)
print(len(s))
# use <TAB>-completion to list all methods available for s
# s.<jupyter_output><empty_output><jupyter_text>4.6) Finishing your sessionPlease make sure to cleanly close your jupyter-notebook sessions - mainly to ensure that all your work and notebooks are properly saved.A rather foolproof procedure is:1. Save your notebook (File -> Save and Checkpoint or key shortcut). Do this from time to time during your work sessions (browser crashes etc.)2. Cleanly close your notebook(s) (File -> Close and Halt)3. Exit your WWW browser4. Type in a shell    ```    user$ jupyter notebook list    Currently running servers:    http://localhost:8888/...    .    .    ```    Note the four digit number after `localhost:`. In our case this is `8888`        ```    user$ jupyter notebook stop 8888   stops the notebook kernel 8888    ```  4.7) Important notes:A few important notes about using the notebook:1. Save often! There is an auto-save in the notebook, but better to also save explicitly from time to time.2. If you accidentally close your WWW browser and you want to reenter your session, you can do the following:   1. Type in a Linux-shell    ```    user$ jupyter notebook list    Currently running servers:    http://localhost:8888/...    .    .    ```       2. Open your WWW browser   3. Type into the adress-field `http://localhost:8888/`, i.e. the address you got from the `jupyter notebook list`-command leaving away everything after the `localhost:XXXX`-string.3. Code *can* be executed in an order different from top to bottom, but note that if you do this variables will not be reset. So for example if you type:<jupyter_code>a = 1<jupyter_output><empty_output><jupyter_text>then go higher up and type:<jupyter_code>print(a)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup