Learn how start, write code in and exit Python interactive sessions in Windows, Ubuntu and Mac OS.
Running Python Code Interactively
00:00
Let’s take a look at running code interactively. First, on Windows. Here we are on the Windows desktop. To run a command prompt, hold down the Windows key and tap R, and then type cmd for command.
00:21
Here, you can see the Command window, and typing python and then hitting Enter will allow us to interact with Python. So you can type the classic thing such as print('Hello World!'), and you’ll see that gets executed.
00:38
You can try some maths. 2 + 5 does equal 7. And you can even assign variables. And later on, you can print the value of those variables out.
00:52
To exit the interpreter, type exit(). To exit the command prompt, just type exit with no brackets.
01:03
Now, running code interactively on Ubuntu. To get to the terminal window, right-click on the desktop and pick Open Terminal. Now in the terminal, you can type python3, rather than just python, and now you can interact with Python.
01:23
Again with the classic print('Hello World!'). Or you can do some maths, and Python will evaluate it straightaway. Or you can assign a variable… and later on print the value of that variable out.