Python Output Text: How to Display Text in Python With Examples
When developing Python applications, displaying information is one of the most common operations. A program often needs to show messages, instructions, results, status updates, or other information to users.
Python provides a built-in function called print() to display text on the screen.
Whether you are creating a simple calculator, developing a web application, automating tasks, or building a data processing tool, understanding how to display text is an essential programming skill.
In this tutorial, you will learn how to display text using Python, combine multiple strings, use quotation marks, format output, and work with special characters through practical examples.
1. Understanding Text Output in Python
Text output refers to displaying readable information generated by a program.
Python uses the print() function to display text in the output console or terminal.
Example 1: Display a Simple Message
print("Welcome to EDUNAVO!")
Output:
Welcome to EDUNAVO!
Let's understand this statement:
-
printis a built-in Python function. -
Parentheses
()contain the information that needs to be displayed. -
Double quotation marks indicate that the value is a string.
-
The text inside the quotation marks is displayed on the screen.
Example 2: Display Multiple Messages
You can use multiple print() statements to display different messages.
print("Welcome to Python Programming")
print("Learn Python Step by Step")
print("Practice Python Every Day")
Output:
Welcome to Python Programming
Learn Python Step by Step
Practice Python Every Day
Each print() call normally displays its output on a separate line.
2. Using Single and Double Quotation Marks
Python supports both single quotation marks and double quotation marks for defining strings.
Example 1: Using Double Quotes
print("Python is a programming language")
Output:
Python is a programming language
Example 2: Using Single Quotes
print('Python is easy to learn')
Output:
Python is easy to learn
Both approaches are valid.
The opening and closing quotation marks must match.
Example 3: Displaying Apostrophes Inside Text
Suppose you want to display:
Python's syntax is readable.
You can use double quotation marks around the complete string.
print("Python's syntax is readable")
Output:
Python's syntax is readable
Alternatively, you can use single quotes around the string and escape the apostrophe.
print('Python\'s syntax is readable')
Output:
Python's syntax is readable
The backslash tells Python to treat the apostrophe as part of the string rather than as the end of the string.
3. Displaying Multiple Pieces of Text Using print()
Python allows you to pass multiple arguments to the print() function.
By default, Python separates these arguments with a space.
Example
print("Welcome", "to", "EDUNAVO")
Output:
Welcome to EDUNAVO
Here, three separate strings are passed to the print() function.
Python automatically inserts a space between them.
Example: Display Student Information
print("Student Name:", "Rahul")
print("Course:", "Python Programming")
print("Learning Platform:", "EDUNAVO")
Output:
Student Name: Rahul
Course: Python Programming
Learning Platform: EDUNAVO
This approach is useful when displaying labels and their corresponding values.
4. Combining Text Using the String Concatenation Operator
Python provides the + operator to combine strings.
This process is called string concatenation.
Example
first_name = "Rahul"
last_name = "Kumar"
full_name = first_name + " " + last_name
print(full_name)
Output:
Rahul Kumar
Let's understand the program:
-
first_namestores the text"Rahul". -
last_namestores the text"Kumar". -
The
+operator combines both strings. -
" "adds a space between the names. -
The resulting string is stored in
full_name.
Example: Displaying a Complete Message
course = "Python Programming"
platform = "EDUNAVO"
message = "Welcome to " + course + " at " + platform
print(message)
Output:
Welcome to Python Programming at EDUNAVO
Important: The + operator can concatenate strings, but you cannot directly concatenate a string and an integer without converting the integer into a string.
For example:
age = 25
# This causes a TypeError:
# print("Age: " + age)
A corrected version is:
age = 25
print("Age: " + str(age))
Output:
Age: 25
The str() function converts the integer into a string.
5. Using f-Strings to Display Dynamic Text
Python supports formatted string literals, commonly called f-strings.
F-strings provide a convenient way to insert variable values directly into text.
An f-string begins with the letter f before the opening quotation mark.
Example
name = "Amit"
course = "Python"
print(f"Hello {name}, welcome to {course} programming!")
Output:
Hello Amit, welcome to Python programming!
Python replaces {name} and {course} with their corresponding values.
Example: Displaying Multiple Variables
student = "Priya"
age = 21
course = "Python Programming"
print(f"Student: {student}")
print(f"Age: {age}")
print(f"Course: {course}")
Output:
Student: Priya
Age: 21
Course: Python Programming
F-strings are particularly useful when generating reports, messages, and dynamic output.
6. Controlling Line Breaks Using the Newline Character
Python supports special characters called escape sequences.
The newline escape sequence is \n.
It moves the output cursor to the beginning of the next line.
Example
print("Python Programming\nEDUNAVO Training")
Output:
Python Programming
EDUNAVO Training
The \n character creates a line break between the two pieces of text.
Example: Displaying a Student Report
print("STUDENT REPORT")
print("--------------")
print("Name: Rahul\nCourse: Python\nStatus: Active")
Output:
STUDENT REPORT
--------------
Name: Rahul
Course: Python
Status: Active
This technique is useful for organizing information into readable sections.
7. Using the Tab Escape Sequence
The \t escape sequence inserts a horizontal tab.
It is useful for separating text into columns.
Example
print("Name\tCourse\tDuration")
print("Rahul\tPython\t30 Days")
print("Priya\tJava\t45 Days")
Output:
Name Course Duration
Rahul Python 30 Days
Priya Java 45 Days
The actual spacing depends on how the terminal or output environment displays tab characters.
8. Displaying Text Without Moving to a New Line
By default, the print() function ends its output with a newline.
However, Python allows you to change this behavior using the end parameter.
Example
print("Hello", end=" ")
print("Welcome to Python")
Output:
Hello Welcome to Python
Normally, the first print() statement would move to a new line.
Here, end=" " replaces the default newline with a space.
Example: Displaying Text on the Same Line
print("Python", end=" - ")
print("Programming", end=" - ")
print("EDUNAVO")
Output:
Python - Programming - EDUNAVO
This is useful when building formatted messages or displaying information continuously on one line.
9. Using the sep Parameter
The sep parameter specifies the separator placed between multiple arguments passed to print().
By default, the separator is a space.
Example 1: Using a Hyphen
print("2026", "11", "03", sep="-")
Output:
2026-11-03
Example 2: Using a Pipe Symbol
print("Python", "Java", "C++", sep=" | ")
Output:
Python | Java | C++
Example 3: Using an Underscore
print("EDU", "NAVO", sep="_")
Output:
EDU_NAVO
The sep parameter helps control how multiple values appear in the output.
10. Displaying Multiline Text
Python supports multiline string literals using triple quotation marks.
You can use either triple double quotes or triple single quotes.
Example
message = """Welcome to EDUNAVO.
Learn Python programming.
Practice with real examples.
Build your programming skills."""
print(message)
Output:
Welcome to EDUNAVO.
Learn Python programming.
Practice with real examples.
Build your programming skills.
This approach is useful when displaying long messages, descriptions, or formatted information.
11. Practical Example: Creating a Course Information Display
Let's combine the concepts learned so far.
We will create a simple program that displays course details.
student_name = "Rahul Kumar"
course_name = "Python Programming"
duration = "30 Days"
platform = "EDUNAVO"
print("================================")
print(" COURSE INFORMATION ")
print("================================")
print(f"Student Name : {student_name}")
print(f"Course : {course_name}")
print(f"Duration : {duration}")
print(f"Platform : {platform}")
print("================================")
print(" Happy Learning! ")
print("================================")
Output:
================================
COURSE INFORMATION
================================
Student Name : Rahul Kumar
Course : Python Programming
Duration : 30 Days
Platform : EDUNAVO
================================
Happy Learning!
================================
This example combines:
-
Variables
-
String values
-
The
print()function -
f-strings
-
Text formatting
-
Multiple output statements
It demonstrates how basic output operations can be used to create a structured information display.
Common Mistakes When Displaying Text in Python
Mistake 1: Missing Quotation Marks
Incorrect:
# print(Welcome to Python)
Correct:
print("Welcome to Python")
Text must be enclosed in quotation marks when written as a string literal.
Mistake 2: Mismatched Quotation Marks
Incorrect:
# print("Hello Python')
Correct:
print("Hello Python")
Always use matching opening and closing quotation marks.
Mistake 3: Incorrect String Concatenation
Incorrect:
# age = 20
# print("My age is " + age)
Correct:
age = 20
print("My age is " + str(age))
Alternatively, use an f-string:
age = 20
print(f"My age is {age}")
Mistake 4: Forgetting the Parentheses
Incorrect:
# print "Hello Python"
Correct Python 3 syntax:
print("Hello Python")
In Python 3, print() is a function and requires parentheses.
Practice Exercises
Try the following exercises to strengthen your understanding.
Exercise 1: Display a Welcome Message
Write a Python program to display:
Welcome to EDUNAVO
Start Learning Python Today
Exercise 2: Display Personal Information
Create variables for your name, age, and city. Display all three values using print().
Exercise 3: Combine Strings
Create two variables containing your first name and last name. Combine them into a full name using the + operator.
Exercise 4: Use f-Strings
Create a program that displays a student's name, course, and duration using an f-string.
Exercise 5: Control Output Formatting
Display the following information using the sep parameter:
Python | Java | C++ | JavaScript
Conclusion
Displaying text is one of the first skills you need to master when learning Python.
The print() function provides several ways to display information, including individual strings, multiple arguments, concatenated text, formatted strings, and multiline messages.
Understanding parameters such as sep and end, along with escape sequences such as \n and \t, will help you create clear and organized output.
Continue practicing these examples before moving on to numerical output and calculations.
Next Tutorial: Python Output Numbers – Learn how to display integers, floating-point values, perform calculations, and format numerical results using Python.