The print() Function and Python Modes

30 min read Getting Started with Python

This is a free course. Log in to run the code exercises and track your progress.

The print() Function and Python Modes

Python is a high-level, interpreted language: the Python interpreter reads a program and runs it line by line. You can use it in two modes.

  • Interactive mode: type one statement at the >>> prompt and see the result at once. Good for quick experiments.
  • Script mode: write the whole program in a file ending in .py, save it and run it. Good for programs you want to keep.

print() shows values on the screen. It puts a space between the values it is given and moves to a new line at the end. The sep and end arguments change this.

print("Hello", "World")           # Hello World
print("2024", "06", "15", sep="-") # 2024-06-15
print("Loading", end="...")
print("done")                     # Loading...done

Anything after a # is a comment. Python ignores it; it is a note for people reading the code.

Python exercise

Read a day, a month and a year from one line and print the date with / between them, using the sep argument of print().

day, month, year = input().split()
print(day, month, year)  # add sep= to join them with /

Log in to edit and run this code.