Your first program

print, text in quotes and the order of execution.

A Python program is a text file with commands. The interpreter reads it from top to bottom and runs the lines one by one. There is nothing to compile in advance: write a line and you can run it.

The first command you will need is print. It shows a value on the screen and moves to a new line. Text goes in quotes, single '...' or double "...", and there is no difference between them. What matters is closing with the same quote you opened with.

print("Hello!")
print('Python runs lines in order')
print(2 + 3)

The last line prints 5: without quotes, 2 + 3 is an expression, and Python evaluates it first. But print("2 + 3") prints the text exactly as written.

You can pass several values to print, separated by commas. By default a space goes between them and a newline at the end. Both can be changed with the sep and end parameters:

print("2026", "11", "19", sep="-")   # 2026-11-19
print("same line", end="")
print("!")                            # same line!

Everything after # up to the end of the line is a comment. Python skips it, while for a human it explains why the code is written the way it is.

Letter case matters: Print("hi") raises NameError, because there is no such function. An unclosed quote gives a SyntaxError before the program even starts: Python cannot tell where the text ends. When you see this error, look at the line it names and at the line before it.

Practice

  1. Text or expression

    What does the line print("2 + 3") output?

    • 2 + 3
    • 5
    • An error
    • Nothing
  2. Separator

    What does the program print?

    print("a", "b", sep="-")
    
  3. The first line

    Print exactly Hello, Tropa — with the comma and the space, and nothing extra.