Lesson 21 of 34
Functions: Your Own Commands
8 min 25 XP
Writing the same code again and again? Make it a function. Start with def, then a name, ( ) and :, and indent the code inside.
Example: edit me and press Run
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.Put parameters inside ( ). The values you pass when calling the function (arguments) arrive in them.
Example: edit me and press Run
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.Defining a function (def) doesn't run it. You have to call it: greet(...)