Skip to content

Your First Python Program

Use print() to show text and values, including the sep and end arguments.

8 min read 10 quiz questions

A program is a set of instructions. print() is one of the most useful first instructions because it displays a result.

Text must be inside quotes so Python knows it is text, not a name.

Example 1: Hello, World!
print("Hello, World!")

Python displays exactly the text between the quotes. This classic first program checks that your code can run.

Example 2: Multiple values
print("Score:", 10)
print(3, 4, 5)

Separate values inside print() with commas. By default, Python puts one space between the values.

Control spaces and line endings

The sep argument chooses the separator between values. The end argument chooses what comes after a printed line; by default it is a new line.

Example 3: sep and end
print("2026", "08", "23", sep="-")
print("Loading", end="... ")
print("done")

The first line uses hyphens instead of spaces. The second print() ends with three dots and a space, so done stays on the same line.

Key points

  • Use print() to display output.
  • Put text inside quotes.
  • Commas let print() show multiple values.
  • sep changes the separator and end changes the ending.

Worked example

Show the result of yesterday's Bangladesh vs India match with two tidy lines.

Example
print("BAN vs IND")
print("Bangladesh scored", 221)

How it works, step by step

  1. The first print() shows the fixture header.
  2. The second print() takes two arguments: text and a number, joined with a space automatically.

References & Further Reading

Related entries from PyLabs's own reference library.

  • print() (Print objects to the text stream file, separated by sep and followed by end.)
  • str() (Convert a value into readable text.)

Your notes

Sign in to keep private notes alongside this lesson.

Sign in to take notes

Practice exercise

Not passed yet

Print the values red, green, and blue on one line, separated by | (a space, vertical bar, and space).

# Write your code below
Want another challenge on this module? More coding practice

Check yourself

Your First Python Program quiz

10 questions. You get instant feedback per question, and the timer starts when you press the button.

Lesson incomplete

Not completed

Create an ID or sign in to save lesson completion across devices.

Create ID to save
Module lesson progress0/5 complete
Module cheat sheet