Running Python Code Interactively
Learn how start, write code in and exit Python interactive sessions in Windows, Ubuntu and Mac OS.
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. To exit Python, exit()
, and to exit the terminal, just type exit
.
01:54
Running Python interactively on macOS. To find a program on Mac, press the Command key and tap Space, and then type the name of the program in question. That gets you into the terminal, where you can type python3
.
02:11 And once again, the commands you’ve already seen will work in the same way. So it’s exactly the same once we get inside Python.
02:24
We exit with exit()
. Again, to leave the terminal, we hit exit
, although to close the window we need to do Command + W, to get back to the desktop.
Become a Member to join the conversation.