This is an archived version of the course. Please see the latest version of the course.

Running Python interactively

Because Python is an interpreted language, you can also run Python interactively, something you will not be able to do with C++.

Type python3 (or python depending on your setup) into the command line.

$ python3
Python 3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

You should get an interactive prompt, which you can now use to type Python code interactively.

Now, type these into the Python prompt:

>>> 1+1
2
>>> "I am a genius"
'I am a genius'

Yes, you are indeed a genius! 😃

This was just actually get you warmed up. We can now start the tutorial for real.

Please follow along and try out the code whilst going through the tutorial. Trying things out yourself is the best way to learn!

If you see a code snippet that looks like the following (with three >>>), it means that I am using an interactive prompt. Remember to indent any blocks if you are inside a block (the interactive interpreter indicates that you are inside a block with three dots ...).

>>> x = 5 + 3
>>> x
8
>>> while x < 10:
...     print(x)
...     x += 1
...
8
9
>>>

Otherwise, it means that the code snippet is a Python script that you should type into a text editor and execute using python3 script_name.py. I recommend typing codes out manually rather than copy-and-pasting – you might notice small things that you might not have realised were important!

If you ever need to exit the prompt, type exit() or quit().