2 Hello

2.1 What topics will we discuss

The Python Universe is enormous! We want to share the minimum necessary for you to do useful things with Python (while still having fun). So the material on this website is not exhaustive, nor do we want them to be. There are more complete resources elsewhere that you should use for reference. Please refer to this section on resources for more details.

Often there are many ways to use Python to achieve the same result. We will usually share the way that allows you to do the most. We just want to get you started; once you are comfortable, you can explore other more advanced methods of using Python.

2.2 Some Tips

  • Remember as little as possible!
    Instead have a few good websites (or notes) that you can access easily.
  • Don’t try to remember syntax
    Instead try to understand how the syntax is structured1.
  • Experiment! Experiment! Experiment!
    Playing with the code does not cost anything. So, be curious. Go with your intuition and try things out. Things won’t work so well at te start but it will
    get better.
  • Keyboard Shortcuts2
    Using the keyboard makes life easy and more efficient. Learn as many as you can.
  • Don’t work alone
    Learning is more fun and faster if you discuss and clarify things with a colleague3.
  • Just learn what you need
    When starting programming it is better to learn the basics and just what you need to solve your problem.

2.3 Python?

What is Python?

Python is a free and friendly programming language. The ‘brain’ of Python is called an interpreter. The newest version of the Python interpreter is Python 3.

How do I use Python?

The Python interpreter can only understand one instruction at a time. Therefore, we usually write many instructions in a single file (code) and then ‘pass’ it onto the interpreter. These files typically have the extension .py. However, Python can also be used interactively using an environment called Jupyter notebook.

One of the best (and easiest) ways to get started with Python is to use an online environment like Colab. However, if want you can also install it on your computer using the Anaconda distribution OR installing it locally on your machine without Anaconda!

2.4 Ways to access Python?

Jupyter Notebooks

Examples of Jupyter Notebooks (from [jupyter.org](https://jupyter.org))

Figure 2.1: Examples of Jupyter Notebooks (from jupyter.org)

There are many ways to issue commands to the Python interpreter. A Jupyter notebook is one very easy (and very popular) environment to write Python4 code. Jupyter notebook also allows you to combine Markdown and Python in the same document to produce rich content that can be easily converted into reports or even interactive presentation slides!

Jupyter notebook files have the extension .ipynb5.

Raw Python

Example of Code Editor such as Sublime Text.

Figure 2.2: Example of Code Editor such as Sublime Text.

Alternatively, if you want something more simple, you can just install Python (see section below) and use the various code editors to run python code. Python files have the extension .py!

Some Pyhton editors that are commonly used include (but not limited to) Sublime Text, Spyder, Visual Studio Code, Atom.

Colab

Example of a Colab notebook.

Figure 2.3: Example of a Colab notebook.

Colab is a (free) platform offered by Google for coding in Python (and some other languages). Colab offers an environment (almost) identical to Jupyter notebook.

Some advantages of using Colab are:

  • Colab will allow us to use Python without having to install it on our computers.
  • Colab will enable us to share our code with others (just like any other Google document)
  • Colab does all the processing on their servers. So, it won’t tax your computer6.

2.4.1 Installing Python

With Anaconda

You do not have to install Python locally on your machine for this workshop. However, if you like to have Python on your computer we recommend that you use the Anaconda distribution called miniconda.

Step 1. Visit the download page at Anaconda.
Step 2. Download and install the 64-bit Python 3 distribution suitable for your operating system.
(Windows users should run Anaconda as Administrator)

Without Anaconda

If you would like to install Python locally on your machine for this workshop or for your own use:

Step 1. Visit the download page at python.org.
Step 2. Download and install the 64-bit Python 3 version (3.7 and above is fine) suitable for your operating system.
Step 3. Ensure that “Add Python to PATH” option is ticked in the installer!
Step 4. Open your favorite editor OR search “IDLE” in your computer to start typing python commands!

Installing packages with command prompt

Step 1. Open run.exe by pressing the windows key AND ‘R’ key

Step 2. Type cmd.exe and click “Ok”

Step 3. type in python -m pip install PACKAGE_NAME and press enter
(replace PACKAGE_NAME with the relevant python packages you would like to install.)

2.5 Conventions

Python code is shown in a grey box like this:

print('Code is shown in a box like this')

A #> will be used to show the result (or output) of the code. This will appear immediately after the code, like this:

print('Code is shown in a box like this')
#> Code is shown in a box like this

2.6 Resources

2.6.1 Jupyter Notebooks

  1. Take a look at this site for some cool tricks and optimisations for these notebooks.