Coding 101 18

Python: Defining Functions

Welcome to Coding 101 - It's the TWiT show that gives YOU the knowledge to live in the wonderful world of the programmer. This week we are introducing our newest module, Python with Code Warrior Dale Chase!

Ivory Tower

Let's Define some Functions!
* Functions can be defined in Python using the "def" keyword in the form "def FunctionName(Variable)"
-- The variable listed in parentheses is the parameter that can be passed to the function when it is being called

Usage:

def myfunction(var1):
... print "Hello World!"

... print var1"

* This example function will print "Hello World" then print the value of the "var1" variable

* If we want to return a value to the code that called the function, we use "return variablename"