Output

Output is the information that a program shows to the user. It is how the program communicates results, messages or data back to the person using it.

In most beginner programs, output usually means text displayed on the screen, such as a message or a calculated result.

Example 1 - Displaying Output in Python

1print("Greetings!")
Show Output

Greetings!

Explanation

This code tells the computer to show the message Greetings! on the screen.

The word print is a built-in Python function that shows information to the user. The text inside the quotation marks (" ") is called a string, which means it is treated as text rather than a number or command.

Example 2 - Displaying Multiple Lines of Output

1print("Hello!")
2print("How are you?")
Show Output
Hello!
How are you?

Explanation

This code uses two print() functions to display two separate messages on the screen.

Example 3 - Combining Variables with Output

1firstName = "John"
2
3print(f"Greetings, {firstName}! How are you?")
Show Output

Greetings, John! How are you?

Explanation

This code creates a variable called firstName and stores the string "John" inside it.

The letter f before the quotation marks means this is an f-string, which allows Python to insert the value of a variable directly into the string.

When the program runs, Python replaces {firstName} with the value stored in the variable.

Example 4 - Using Multiple Variables in Output

1firstName = "John"
2lastName = "Doe"
3
4print(f"Goodbye, {firstName} {lastName}.")
5print("We hope to see you again soon!")
Show Output
Goodbye, John Doe.
We hope to see you again soon!

Explanation

This code creates two variables, firstName and lastName, which store the strings "John" and "Doe".

The first print() line uses an f-string, which allows Python to insert variable values directly into the text. When {firstName} and {lastName} are used inside the f-string, Python replaces them with the values stored in the variables.

The second print() statement displays another line of text on the screen.