Introduction To Python Lecture 2: Introduction To Jupyter: Pavlos Antoniou
Introduction To Python Lecture 2: Introduction To Jupyter: Pavlos Antoniou
Lecture 2: Introduction to
University of Cyprus
Jupyter Department of
Computer Science
Pavlos Antoniou
The Python Interpreter
• Python is an interpreted language: program code is read, translated
to machine language and executed line by line by the Python
interpreter
– This stands in contrast to compiled languages (such as C, and C++)
– In compiled languages, entire program code is translated into machine
language before you ever run it by the compiler (executable file is created).
– Executable file is read and executed by the target machine as many times
we want (source code file and compiler are not involved during execution).
• So, whenever you want your Python code to run, you give it to the
Python interpreter
Launching the Python Interpreter
• There are many ways to launch the Python interpreter
hello.py
.ipynb files
• Within JupyterLab (or Jupyter Notebook), a python program is
written into a .ipynb file called notebook
• .ipynb files combine Python code with narrative text, mathematical
equations, visualizations, interactive controls, and other rich output
– .ipynb can be edited and executed only via JupyterLab or Jupyter Notebook
MyFirstAnacondaNotebook.ipynb
Jupyter
• Official website: https://jupyter.org/
1
Cells
• Jupyter notebook consists of cells
• Τwo main cells types:
– code cells (default cell type)
– markdown cells
• You can alter the cell type using the pulldown menu in the toolbar of
your Jupyter notebook.
Code cells
• A code cell contains actual code that you want to run
• Execute the code in a code cell by selecting it and:
– clicking on the Run triangle or
– hitting the Enter while holding down the Shift key (denoted Shift + Enter).
• Code cells are executed in the order you shift-enter them
• If you did not explicitly
execute a cell early in
the document, its
results are not known This cell was not executed by user
x is not defined; y cannot be evaluated
to Python interpreter
and cannot be used in
the next cells
Code cells: Examples
• Below is an example of a code cell printing hello, world.
• Notice that the output of the print statement appears in the same
cell, though separate from the code block
• The number in the square brackets to the left of each cell indicates
the execution order of the cell
• While a cell is being executed, an asterisk (*) appears within the
square brackets to the left of the cell [*]. Once the execution
terminates, a number (execution order) replaces the asterisk.
Markdown cells
• Markdown cells contain text (such as titles, subtitles, paragraphs,
etc.), links (internal or external), or other graphics (such as images)
• See APPENDIX for language’s syntax, see next slide for examples
Markdown cells