Concepts / Python's Vocabulary: Reserved Words and Your First Sentence

Python's Vocabulary: Reserved Words and Your First Sentence

Python code you write in the course editor is read by a Python interpreter, which executes your instructions and displays output on your screen.

  • Programming

From Instructions to Output

Python is a programming language: a formal system for giving instructions to a computer. When you write Python, you express instructions in a format that both people and computers can understand. The computer reads those instructions through a Python interpreter, executes them, and displays results such as text, numbers, or error messages on your screen.

run codedisplay resultCourse editorPython codePython interpreterReads and executesinstructionsOutput areaText, numbers, or errors
How does code written in the course editor move through the Python interpreter and become output on the screen?

The editor is where you write. The interpreter is the program that reads what you wrote and performs the requested actions. The output area is where you see the result. These are connected, but they are not the same thing: text sitting in the editor has not yet been executed.

Your First Python Statement

The simplest way to make Python display something is to use print. The print function is a built-in tool for displaying text, numbers, and other values. It requires parentheses, and the value you want to display goes inside those parentheses as an argument.

python
Output
Hello, World!

Reading the First Statement

What happens when the statement print("Hello, World!") is run?

Read print: The interpreter reads the word print and recognizes it as a function.

Read the argument: The text Hello, World! appears inside quotation marks, so Python treats it as a string.

Call the function: The parentheses show that print is being used with the string as its input.

Display the result: The print function displays the string in the output area.

The text Hello, World! appears on the screen.

Python's Vocabulary

Beginning programmers need to separate two kinds of words in code. Some words belong to Python's vocabulary and rules. The source raises tokens such as for and in as examples of words to examine when deciding which parts of code are defined by Python. Other names are choices made by the programmer, such as names connected with words, pizza, or slices. Python does not have a human understanding of pizza or slices; it follows the language rules represented by the code.

A reserved word is a word defined by Python for use in the language's rules rather than a freely chosen name. When reading an example, ask which parts must follow Python's vocabulary and syntax and which parts are simply names selected by the programmer.

The first statement also shows this distinction. The word print is not a name you invented for this line; it is a built-in Python tool. The text inside quotation marks is data supplied to that tool. The quotation marks tell Python that the characters are a string rather than a command or a variable name.

Text, Numbers, and Values

Quotation marks change how Python interprets what you write. A string is text surrounded by quotation marks. A number is written without quotation marks. Python treats these values differently internally, even when their printed appearance looks similar.

python
Output
42
3.14
15

The first statement prints the number 42, and the second prints the decimal number 3.14. In the third statement, Python evaluates 10 + 5 and then print displays the result, 15. By contrast, "42" would be a string because the quotation marks identify it as text. The string "42" and the number 42 may look alike in the output, but Python treats them as different kinds of values.

Writing Versus Running

Writing code and running code are separate actions. When you type print("Hello") into the editor, you have written an instruction, but the instruction is only waiting in the editor. When you press the control that runs the code, or the course environment triggers execution, the interpreter reads and performs it.

thentriggersproducesWrite codeStatement in editorRun codeExecution is triggeredRead instructionsInterpreter processes codeDisplay outputResult or error
What changes between the moment a Python statement is written and the moment it is run?

Treat the editor as a workspace, not as an output screen. You can write code, review it, edit it, and run it again. If the interpreter reports an error, correct the code and repeat the cycle.

Top-to-Bottom Execution

A program contains one or more statements. Python executes multiple statements sequentially, from top to bottom. Each line is a separate instruction in the example below, so the output appears in the same order as the statements.

print("First") print("Second") print("Third")

The Course Workspace

You do not need to install Python on your computer for this course. The course provides a built-in environment in your browser. When a lesson includes a code example or practice exercise, you can type Python statements into the editor and run them through the connected Python interpreter. The result appears in an output area below or beside the code.

opensubmit codeshow execution resultLesson or exerciseCode editor appearsType statementsWrite Python codeRun controlTrigger executionOutput areaResult or error message
Where do you enter Python code, and what happens when you use the control that runs it?

This arrangement lets you experiment immediately. You can change a statement, run it again, compare the output, and observe what happens when the interpreter finds a mistake.

Mistakes Beginners Make

  • Assuming that typing code automatically runs it

    Writing and running are separate actions. The interpreter does not execute the statement until execution is triggered.

    Fix: Write the statement in the editor, then run it and inspect the output area.

  • Leaving quotation marks out of a text value

    Quotation marks tell Python that the characters are a string rather than a command or variable name.

    Fix: Write the text as a quoted string, as in print("Hello").

  • Putting quotation marks around a number when you intend a numeric value

    Quotation marks make 42 a string. The string "42" and the number 42 are different to Python.

    Fix: Use print(42) when the value should be written as a number.

  • Changing syntax that Python requires

    The print function requires parentheses around the value it receives.

    Fix: Use print("Hello") with parentheses and quotation marks in the appropriate places.

  • Treating every word in an example as a fixed Python word

    Some parts of code come from Python's vocabulary, while other names are choices made by the programmer. Python does not fundamentally understand pizza or slices.

    Fix: Separate Python-defined vocabulary and syntax from names selected by the programmer.

Try the Interpreter

EASY

Use the course editor to run a few print statements. Print a string, print a number, and print an expression. Then change one statement and run the code again. Before each run, predict what will appear in the output area.

Hints
  • Put text inside quotation marks.
  • Write numbers without quotation marks when you want Python to treat them as numbers.
  • The expression 10 + 5 produces the value 15 before print displays it.

What do you think happens?

What will the following three statements display, and in what order?

  • First, Second, Third
  • Third, Second, First
  • All three values on one line
Reveal answer

Answer: First, Second, Third

Python executes statements sequentially from top to bottom, and each print statement displays its value in that order.

Key Takeaways

  • Python code is written in the course editor, read by the Python interpreter, and displayed as output in the output area.
  • The print function displays values and requires parentheses around the value being printed.
  • Quotation marks identify strings, while numbers are written without quotation marks and are treated differently by Python.
  • Writing code and running code are separate actions, so you can edit, execute, inspect, and run code again.
  • Python executes statements from top to bottom, and learning to distinguish Python vocabulary from programmer-chosen names helps you read code accurately.