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?

19th Jul 2018, 12:46 PM
Nitin Gutte
Nitin Gutte - avatar
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
19th Jul 2018, 12:55 PM
giannismach
giannismach - avatar
+ 3
Maninder Singh your code has a bug. Return does not need parentheses (although print does). def h(): return 5 print(h())
19th Jul 2018, 4:30 PM
giannismach
giannismach - avatar
+ 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.
19th Jul 2018, 4:18 PM
Maninder $ingh
Maninder $ingh - avatar
+ 2
Lucky Luke sorry for mistake.
20th Jul 2018, 12:33 AM
Maninder $ingh
Maninder $ingh - avatar
+ 2
Nitin Gutte You 're welcome!
20th Jul 2018, 8:07 AM
giannismach
giannismach - avatar
+ 1
Thank u Guyzzz
20th Jul 2018, 3:47 AM
Nitin Gutte
Nitin Gutte - avatar