6 Answers
+ 8
Alex ,
use of print() and return:
âŞď¸print uses arguments, that are sent to standard output (< screen > by default), if no arguments are given, nothing will be displayed
âŞď¸print() adds a newline character "\n" at the end of each call, except the < end > argument is used
âŞď¸print can be used in main program or in functions
âŞď¸return can only be used in functions. return can be followed by argument/s, that are given back to the caller. if no argument or no return is used < None > will be returned
âŞď¸the argument/s returned from the function can be stored in a variable and can be used for further processing.
âŞď¸return will stop the execution of the function immediately and gives the control flow back to the caller
example function:
a program uses part numbers which must have a defined formatting.
the main program calls a function < chk_pn(inp) > and passing the part number in variable < inp >.
the function checks it an returns < True > or <False>
main program gets the returned value and can handle it.
+ 2
+ 1
Print can be used anywhere in the program but return statement should only be used in the function.
0
Thanks!