I know echo()
and print()
do the same thing. but print has a return value of (int) 1
.
The question is:
Since this is the purpose of print() , the function doesn't need to return anything useful, so you get None as a return value. Note: The Python interpreter doesn't display None .
The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print.”
One important thing to remember is that Python print() returns no value.
print just shows the human user a string representing what is going on inside the computer. The computer cannot make use of that printing. return is how a function gives back a value. This value is often unseen by the human user, but it can be used by the computer in further functions.
print
is a function and can be used in expressions, while echo
is a language construct that can only be used at the start of the line.
echo print(print(print(print(123)))), print(4);
The real use case for having print available as a function is to allow it to be used in expressions. For example as debug feature:
if (($a == $b) and print("It's true") and $c) {
Or even
return TRUE and print("right");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With