What is Python?

Python is a general purpose programming language that supports rapid development of scripts and applications.

Python's main advantages:

  • Open Source software, supported by Python Software Foundation
  • Available on all platforms
  • "Batteries Included" philosophy - libraries for common tasks available in standard installation
  • Readable
  • Supports multiple programming paradigms
  • Very large and amazing community

Created by Guido van Rossum around 1991.

Whad does it mean readable?


In [1]:
# can you guess what this code is doing?
def print_sum(x, y):
    z = x + y
    print(z)

The code is well structured and as you can see we don't use curly brackets ({}) around the code as in other languages. Python uses indentation.

Python is also dynamic, it means that we don't have to declare our variables before using them.

Interpreter

Python is an interpreted language. As a consequence, we can use it in two ways:

  • Using interpreter as an "advanced calculator" in interactive mode:
user:host:~$ python
Python 3.5.1 (default, Oct 23 2015, 18:05:06)
[GCC 4.8.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> message = "Hello World"
>>> print(message)
Hello World
  • Executing programs/scripts saved as a text file, usually with *.py extension:

Create a file called hello.py and put this text inside:

# Output should be 'Hello there'
message = "Hello World"
print(message)

Then from the terminal (or powershell if you use windows) type:

python hello.py

The advanced calculator is called REPL, Read Evaluate Print Loop

As you can see the result is the same, we printed the variable called message.

Jupyter

Short story of Jupyter

Jupyter is the new name for what once called IPython Notebook. The name has 2 purposes:

  • underline the strong connection with science and with the first notebook wrote by Galileo Galileo in which data and analysis are put together, in the first notebook Galileo Galilei was studying Jupiter
  • The strong connection with 3 languages, Julia, Python and R

Jupyter today is a big collection of projects, including Jupyter Notebook, JupyterHub, the new JupyterLab and many others.

Jupyter notebook brings an enchanced REPL experience inside your browser, basically you can run Python commands from your browser and Jupyter Notebook will take care of execute them. Under the hood this process is done by the Jupyter Notebook, a communication protocol and a kernel (generally IPython)

Why do we use Jupyter?

Jupyter provides a convenient platform to learn coding.

It uses a browser, something we are all very comfortable with, to edit and run your code.

It's also a widely used library inside the Python and Data community.

How to run and save your code

To run jupyter you need to open the terminal/console and type:

jupyter-notebook

or

jupyter notebook

If you have a notebook open you should see a top menu (File, Edit, View...) a series of buttons under it (floppy disk, plus, scissor...)

Challenges: take around 5 to resolve each of the following challenges

Try to use the advanced calculator (REPL) if you get stuck in and you want to exit you need to type exit()

Is there something that surprises you?