What is the difference between return statement and print statement ....? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 6

What is the difference between return statement and print statement ....?

14th Mar 2018, 1:26 PM
Kala Nandini
Kala Nandini - avatar
2 ответов
+ 6
I'll start with a basic explanation. 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. On a more expansive note, print will not in any way affect a function. It is simply there for the human user's benefit. It is very useful for understanding how a program works and can be used in debugging to check various values in a program without interrupting the program. return is the main way that a function returns a value. All functions will return a value, and if there is no return statement (or yield but don't worry about that yet), it will return None. The value that is returned by a function can then be further used as an argument passed to another function, stored as a variable, or just printed for the benefit of the human user. Hope it helped.
14th Mar 2018, 1:55 PM
Ratnesh Mishra
Ratnesh Mishra - avatar
+ 1
Thanks for the info, helps lot
14th Mar 2018, 7:14 PM
KUMARAN
KUMARAN - avatar