Can anyone explain me the 'return' statement in Python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can anyone explain me the 'return' statement in Python?

Could not understand it so please help me understand the it in easy way.

6th May 2022, 4:21 PM
Ruhullah
Ruhullah - avatar
2 Answers
+ 6
RUH ULLAH , the return statement can only be used from inside a function. let us assume we need to get values as input and they have to be of integer data format in a range from 1 upto 8. we need this repeatedly in our program. instead of writing the code multiple times, we are going to create a function, that can be used (called) each time we need this kind of input. the function has to perform these tasks: - take input of the number - check if it is a valid integer number - give it back to the main program this last step will be done by using return. by doing so, the value we are returning can be taken in the main program and used for further purposes. after using the return statement, the function will be terminated and the control flow is handled by the main program. sample: https://code.sololearn.com/c2zmmfLsd2dg/?ref=app
6th May 2022, 5:02 PM
Lothar
Lothar - avatar
+ 6
https://code.sololearn.com/cpGThocHw9cA/?ref=app
6th May 2022, 4:28 PM
Slick
Slick - avatar