In Python, output means displaying information on the screen. The most commonly used function for displaying output is print().
Output is the information displayed by a program after processing data.
For example:
print("Hello World")
The print() function is used to display information on the screen.
print("Welcome to Python")
You can use print() as many times as required.
print("Hello")
print("Welcome")
print("Python")
Text is written inside quotation marks when using the print() function.
print("My name is Rahul")
print("I am learning Python")
Numbers can be printed without quotation marks.
print(10)
print(100)
print(99.50)
The print() function can display the value stored in a variable.
name = "Rahul"
age = 20
print(name)
print(age)
You can pass multiple values to print(). Python separates them with a space by default.
name = "Rahul"
age = 20
print(name, age)
You can print text and variables together.
name = "Rahul"
age = 20
print("Name:", name)
print("Age:", age)
The print() function can also display the result of an expression.
print(10 + 20)
print(50 - 20)
print(5 * 4)
a = 10
b = 20
print("Sum:", a + b)
print("Difference:", a - b)
print("Product:", a * b)
The sep parameter controls what is placed between multiple values printed by print().
print("Python", "Java", "PHP", sep=", ")
By default, the separator is a space.
print("2026", "09", "20", sep="-")
You can use different characters as a separator.
By default, print() moves to a new line after displaying output. The end parameter can change this behavior.
print("Hello", end=" ")
print("World")
print("Python", end=" - ")
print("Programming")
The \n escape sequence is used to create a new line.
print("Hello\nWorld")
The \t escape sequence inserts a tab space.
print("Name\tAge")
print("Rahul\t20")
You can use different quotation marks to display quotes inside a string.
print('He said "Hello"')
You can also use escape characters when necessary.
print("He said \"Hello\"")
F-strings provide a convenient way to insert variables inside strings.
name = "Rahul"
age = 20
print(f"My name is {name}.")
print(f"I am {age} years old.")
The print() function can display collection data such as lists.
fruits = ["Apple", "Banana", "Mango"]
print(fruits)
name = "Rahul"
age = 21
course = "Python"
print("----- Student Details -----")
print("Name:", name)
print("Age:", age)
print("Course:", course)
print("Status:", "Active")
Question: Which function is used to display output in Python?