Python Output
6 min read ·
What is Output in Python?
print() function.print() function.The print() function is one of Python's built in functions. It is used to display output on the screen.
Python print() Function
print() function is very simple.Printing Text
Output
Output
Printing Multiple Lines
print() function as many times as needed. Each print() statement displays its output on a new line.Output
print() statement.Suppose you are creating a student report card application. You may want to display the student's name, roll number, and marks on separate lines. Using multiple print() statements makes the output clean and readable.
Using Single Quotes and Double Quotes
' ') or double quotes (" ").Output
Most Python developers prefer double quotes for strings because they improve readability, but both single and double quotes are equally valid.
What Happens if Quotes are Missing?
Hello. Since no such variable exists, it produces an error.Output
Whenever you want to display text, always enclose it in either single quotes or double quotes.
Printing Numbers
Output
Printing Variables
print() function can also display the value stored inside a variable.Output
Printing Expressions
print() function can display the result of mathematical expressions.Output
Printing Multiple Values
print() statement by separating them with commas.Output
Using the sep Parameter
sep parameter changes the separator between multiple values.Output
Output
Using the end Parameter
print() statement ends with a new line.Output
end parameter.Output
Output
end parameter replaces the default newline character with the value you provide.The end parameter is useful when displaying progress messages, menus, or formatted output where multiple values should appear on the same line.
Common Mistakes
Forgetting Quotation Marks
Forgetting Parentheses
print() function call.Missing Closing Quote
Always check that every opening quotation mark has a matching closing quotation mark.
Best Practices
sep parameter to format multiple values clearly.end parameter only when you intentionally want output on the same line.You have learned how to display output in Python using the print() function. You also know how to print text, numbers, variables, expressions, multiple values, and how to customize the output using the sep and end parameters.
Exercise
print() statements.print() statement.25 + 15."Python", "Java", and "C++" separated by " | "."Hello" and "World" on the same line using the end parameter.