From 9dc43f40e0f1d4e04626a1d7a06f4e1aac3be175 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Wed, 20 Sep 2017 21:37:33 -0400 Subject: [PATCH] Update python.md --- python.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/python.md b/python.md index 5caad5f..da7dc96 100644 --- a/python.md +++ b/python.md @@ -14,6 +14,7 @@ 1. Get user input 1. Repeatedly perform a set of commands 1. Use a for loop +1. Define a function 1. Create a class for an object 1. Have a class inherit from another 1. Create a factory for objects @@ -224,6 +225,35 @@ for x in range(0, 3): Simplify the last set of activities using a `for` loop +## Define a function + +If you have a routine that you run over and over again, you can define your own function: + +```python +def greet(): + print('hi') + +greet() +``` + +Functions can take parameters which alter their functionality: + +```python +def greet(name): + print('hi, ' + name) + +greet('bob') +``` + +Functions can return values: + +```python +def add(value1, value2): + return value1 + value2 + +print(add(1,3)) +``` + ## Create a class for an object You can use a `class` or blueprint for objects that you'll use