Meet Python
A program is a sequence of instructions. Python is a language for writing those instructions, and an interpreter is the software that runs them. You can experiment here in the browser before installing anything.
What actually runs?
When you write Python, you create text that follows the language’s syntax. The Python interpreter reads that text, executes instructions and can display results. The .py file is your source code; it is not a standalone Windows executable.
In a terminal, python or py launches an installed interpreter. At a Python prompt (>>>), you can enter instructions one at a time. A script groups those instructions in a file and runs them together.
Three ways to practise
The CF playground runs supported Python code inside your browser through a WebAssembly runtime. It does not need a CF account, and it cannot inspect your Windows devices or read ordinary files from your computer.
On your own computer, install Python from its official distribution, verify its version in a terminal, save a file such as hello.py, and run it with python hello.py or, on many Windows machines, py -3 hello.py. A local terminal has different permissions from the browser.
Make a script on your own computer
When you are ready to work outside the browser, obtain Python from the official Python site (python.org/downloads) and follow its instructions for your operating system. On Windows, open a terminal and try py -3 --version; on many other systems use python3 --version. If the command is not found, check the installation and your system’s command-launch configuration rather than guessing.
Create a plain-text file called hello.py containing print("Hello from a file!"). Save it with the .py extension, not .py.txt. In a terminal, change into its folder and run py -3 hello.py on Windows (or python3 hello.py where appropriate). The printed line should match the file. Keep the source file; it is yours to edit and reuse.
Read an instruction
A function can perform an action. print() writes the text representation of values to standard output. Parentheses contain the arguments passed to the function. Quotation marks indicate that the contents are text.
Python runs the first line before the second line. Indentation and syntax matter; we will study them as the course develops.
Try it yourself.
Choose a starting example or write something completely different. You control the code; the Run button executes what is in the editor, not a hidden preset.
Print a short message using Python’s output function.
Press Run Python to execute the editable code.
Change the message to something of your own and run it again.
Need a hint?
Only change the text between quotation marks.
On first Run, a pinned Python runtime downloads from jsDelivr. Code executes locally in your browser's Web Worker, not on our server. It cannot inspect your normal PC files or Windows hardware. Avoid entering secrets. Heavy/infinite loops are stopped by a time limit.
Check your understanding.
Try answering each question before opening its reference answer. Explain the idea aloud or change an example to test it for yourself.
What is the difference between a .py file and the interpreter that runs it?
View answer
A
.pyfile is a text file containing Python source instructions. The Python interpreter is the program that reads and executes those instructions. The file is not itself an executable interpreter:python hello.pyruns that script with Python.Why can a browser-based Python playground not inspect Device Manager?
View answer
The playground runs in a browser sandbox, which cannot directly inspect Windows Device Manager or your installed drivers. Browser access to local hardware and operating-system APIs is intentionally restricted. A driver-inventory program would need to run locally with suitable permissions.
Where this leads.
Later we will use these same instructions in command-line tools, but first we need to learn how values work.