The simplest Python program is a sequence of instructions, written one per line, and executed one by one from top to bottom. Our first program only has two instructions. Here is the program again, already run for you. (If you’re reading this tutorial on a narrow screen you may just see the result of running the code. To see the code itself, click on the pencil icon.)
Remember to open the link to Python in a new tab.
The first instruction is an assignment: the computer evaluates the expression to the right of the assignment (=) and stores the result in the variable on the left of the assignment. Each piece of data we need has to be stored in a variable. Translating Python to English, the assignment states ‘let result be the sum of 3 and 7’.
The second instruction, print, prints some text on the screen, followed by the computed result. Note the following:
- the comma separates the two things to be printed, in the same way we use commas in English to enumerate two, three, or more things;
- text is written between double-quotes, which are not printed themselves. In Python, a sequence of characters surrounded by double-quotes is called a string.