Understanding Output in Python

Pyhton (7 Part Series)

1 Understanding Output in Python
2 Understanding Variables in Python
3 more parts…
3 Python Data Types – A Beginner’s Guide
4 Mastering Python Output Formatting: Aligning, Padding & More
5 Python Operators: Arithmetic and Logical Operators Explained
6 Mastering Python Operators: Comparison, Bitwise & Assignment
7 Python If-Else Statement Explained (With Examples)

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
23 + 24 = 47
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*)
print(*arguments*)
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!")
print("Hello, World!")
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)
print(23 + 34)
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")
print("23 + 34")
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)
print("The sum of 23 and 34 is:", 23 + 34)
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).

Pyhton (7 Part Series)

1 Understanding Output in Python
2 Understanding Variables in Python
3 more parts…
3 Python Data Types – A Beginner’s Guide
4 Mastering Python Output Formatting: Aligning, Padding & More
5 Python Operators: Arithmetic and Logical Operators Explained
6 Mastering Python Operators: Comparison, Bitwise & Assignment
7 Python If-Else Statement Explained (With Examples)

原文链接: Understanding Output in Python

© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享
No matter how you feel, get up, dress up and fight for your dreams.
无论你现在感觉如何,请起床、穿好衣服然后为你的梦想而奋斗
评论 抢沙发

请登录后发表评论

    暂无评论内容