Hi everyone!
This time I am going to post answer to one of the most frequently asked question
: Differences between print statement and return statement in Python.
- The print statement prints a string, variable etc.
- It seems that return statement also print the statement, but actually it returns the string, variable etc when the function is called.
- The print statement prints it for the benefit of the user. The computer cannot make use of that printing.
- While the return statement can be used by the computer in further functions.
Now I will
show an example how these statements are different(code):
Here a function called example is defined which prints the value 1 and
returns the value 2. When we call the function it prints both 1 and 2. This may
seem confusing and we think they are similar. Then we assign the function to a
variable and the number 1 is printed. But when we print the variable it only
shows the value 2. From this we can understand that the print statement can’t
be used for other functions while the return statement can.
Hope this will help you. If you have any doubts please ask in the comments section. Bye
Hope this will help you. If you have any doubts please ask in the comments section. Bye

I found this answer very helpful. It cleared all my doubts regarding the print statement and return statement.
ReplyDeleteGlad it found helpful!
Delete