0
When do we use print and when do we use return in Python?
Does using either of them in the wrong context create an error?
6 Answers
+ 3
Print is used to produce output.
Return is used to produce a value that can be used later.
Print can be used anywhere, while return can only be used inside a function.
Here are the related lessons:
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2287/?ref=app
https://www.sololearn.com/learn/Python/2426/?ref=app
+ 3
Maninder Singh your code has a bug. Return does not need parentheses (although print does).
def h():
return 5
print(h())
+ 2
In functions use return but you can use print also in functions and print mostly used for see outputs but you can also see your return value with the help of print .
e.g
def h():
return 5
print(h())
here return used for return int value from function and print used in to see the return value.if you never use print here you cannot see the return value.
+ 2
Lucky Luke sorry for mistake.
+ 2
Nitin Gutte You 're welcome!
+ 1
Thank u Guyzzz