DEV Community

Cover image for 🚀 Understanding Output in Python
Divya Dixit
Divya Dixit

Posted on

🚀 Understanding Output in Python

1. What is Output?

Output refers to anything that appears on the screen or is provided by the computer after performing a task or operation.

For example, if you tell a computer to add two numbers (23 and 24), it will process the operation and return a result:

23 + 24 = 47
Enter fullscreen mode Exit fullscreen mode

This result (47) is called output.

What is Input?

Whatever data we provide to the computer is called an input. In the above example, we provided 23 and 24 so they are inputs, and 47 is the output.

🔹 Printing Output in Python

Python makes printing output super simple! Unlike other programming languages, Python does not require extra formalities or lengthy syntax.

Python provides the print() function, which is used to display output on the screen.

📌 Syntax of print() Function:

print(*arguments*)

Enter fullscreen mode Exit fullscreen mode

Here, arguments refer to the values or text or anything you want to print.

🔹 Example 1: Printing a Word or Sentence

To print a word or sentence, we write it inside double quotes ("") or single quotes ('').

print("Hello, World!")
Enter fullscreen mode Exit fullscreen mode

💡 Output:
Hello, World!

✅ Whatever is written inside quotes is printed exactly as it is.

🔹 Example 2: Printing a Mathematical Calculation

print(23 + 34)

Enter fullscreen mode Exit fullscreen mode

💡 Output:
57

Here, Python calculates the sum and prints the result.

🔹 Example 3: Printing a Number as Text

But if we write numbers inside double quotes, Python will treat them as text (string), not numbers.

print("23 + 34")

Enter fullscreen mode Exit fullscreen mode

💡 Output:
23 + 34

🔹 Why? Because "23 + 34" is inside double quotes, so Python prints it as it is, without calculating.

🔹 Example 4: Printing Multiple Values

You can print multiple values in a single print() statement using commas.

print("The sum of 23 and 34 is:", 23 + 34)

Enter fullscreen mode Exit fullscreen mode

💡 Output:
The sum of 23 and 34 is: 57

Python automatically adds a space between values when separated by commas.

🎯 Conclusion

✔ Output is what the computer returns after performing an operation.
✔ Input is the data given to the computer.
✔ Python uses the print() function to display output in a simple way.
✔ Text must be written inside double or single quotes ("text" or 'text').
✔ If a number is written inside quotes, it is treated as text (not calculated).

Top comments (0)