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:
print("Welcome to Python Programming")
You can call the print() function multiple times. Each call displays output on a separate line by default.
Example:
print("Python is easy to learn")
print("It is powerful and flexible")
print("I enjoy writing Python code")
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:
print("Learning Python step by step")
print('This message also prints correctly')
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:
print(Python is fun)
Output:
SyntaxError: invalid syntax
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:
print("Good Morning", end=" - ")
print("Have a great day!")
Output:
Good Morning - Have a great day!
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:
print(7)
print(120)
print(9846)
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:
print(10 - 4)
print(6 * 8)
print(20 // 3)
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:
print("My score is", 92)
print("Total items:", 15, "units")
Using commas is a simple and safe way to mix different data types in one output without causing errors.
