How do I create (define) and use (call) a function in Python?

1) Creating a function is easy. First you must define the function. There are 3 parts: "def", the name and the parenthesis / colon. You always write the word "def" before the name, it means define.

2) After you have "defined" the function you then put your code INDENTED underneath the function. Thats how we know that code belongs to the function.

3) Finally after defining we then need to tell Python when to use our function, or call it. This is very simple, its just your function name with parenthesis next to the name, please note theres no colon after the parenthesis.

4) Now anything you write in your function will be executed when you "call" the function. This can make your code faster and more organized. You will understand more as you progress in your CS journey.

© 2020 Farragut Technology Program