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).

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay