3. Program with functions

3.1. Functions

  • Functions are shareable codes

  • I define a name and call the function throughout the program

  • The function must be defined before it can be called

  • If you want to return a value to the subject that calls the function, you must use the return command

3.2. Program with functions

3.3. There are no stupid questions

  • Is the return command the same as printing? No, print() shows something on the screen, while return returns a value to the function caller.

  • If there is no return inside the function, what does it return? It returns nothing: None. Should return always appear at the end of the function? Not always, depends on the logic of the function.

  • Can a function return more than one value? Yes, including lists or dictionaries.

You have attempted of activities on this page