Python Output Using print()
In Python, the print() function is used to show messages, values, or
results on the screen. It is one of the most basic and frequently used
functions in any Python program.
Example:
You can call the print() function multiple times. Each call displays output
on a separate line by default.
Example:
Using Quotes for Text
Any text (string) you want to print must be enclosed within quotation
marks. Python allows you to use either double quotes (" ") or single quotes
(' ').
Example:
Both styles work the same way, so you can choose whichever you
prefer.
If you forget to use quotes around text, Python will not understand it and
will raise an error.
Incorrect Example:
Output:
SyntaxError: invalid syntax
Try it Yourself
This happens because Python treats unquoted text as code, not as a
string.
Printing on the Same Line
Normally, print() moves the cursor to a new line after printing. However,
you can change this behavior using the end parameter.
Example:
Output:
Good Morning - Have a great day!
Try it Yourself
Here, the end value replaces the default newline and allows the next output
to continue on the same line. Adding spaces or symbols inside end helps
improve readability.
Printing Numbers in Python
The print() function is not limited to text—it can also be used to show
numeric values such as integers or results of calculations. Unlike strings,
numbers should not be written inside quotation marks.
Example:
These statements directly display the numeric values on the screen.
Printing Calculations
Python allows you to perform arithmetic operations inside the print()
function. The expression is evaluated first, and then the result is
displayed.
Example:
This makes print() very useful for checking calculations while learning or
debugging code.
Combining Text and Numbers
You can display both text and numbers together by separating them with
commas inside the print() function. Python automatically formats them into a
single readable output.
Example:
Using commas is a simple and safe way to mix different data types in one
output without causing errors.
