๐ Python Mistakes Everyone Makes ❌
Day 2: Assuming print() Returns a Value
One of the most common beginner mistakes in Python is thinking that print() returns a value.
It doesn’t—and this misunderstanding often leads to confusing bugs.
Let’s break it down simply.
❌ The Mistake
❓ What happens here?
"Hello" is printed on the screen
-
Then None is printed
Why? Because print() does not return anything.
❌ Why This Fails
The print() function is only used to display output on the screen.
It does not send any value back to be stored in a variable.
So this line:
result = print("Hello")is actually the same as:
result = None✅ The Correct Way
If you want to store a value, assign it directly to a variable and then print it.
message = "Hello"✔ The value is stored
✔ The value is displayed
✔ No confusion
๐ง Simple Rule to Remember
print() → shows the value
return → gives the value back
Example:
def greet():Here, return sends the value back, and print() simply displays it.
✅ Key Takeaway
Never expect print() to give you a value.
Use it only for displaying output, not for data storage or logic.
%20returns%20a%20value%20(1).png)

0 Comments:
Post a Comment