Functions
colon 
start with ‘def’ 
function name 
arguments 
deftwotimes(n): 
return2*n 
‘return’ precedes 
the value to be sent back 
No declaration of types 
of function or arguments
New definition?
New definition?
New definition?
Popquiz! 
What happens now?
Popquiz! 
What happens now?
No ‘overloading’
More functions
What does this mean?
Functions can be arguments
Functions can be arguments
We can also use an “anonymous function”
Using parameters
Why Python? 
•Easy to learn syntax 
•Built-in datatypes for lists, strings etc. 
•Runs on many types of machines 
•Many scientific librartes (SciPy, NumPy) 
•Large community of scientists using it 
•#1 programming language in universities 
•Shell mode for experimentation
Why Python? 
•Easy to learn syntax 
•Built-in datatypes for lists, strings etc. 
•Runs on many types of machines 
•Many scientific librartes (SciPy, NumPy) 
•Large community of scientists using it 
•#1 programming language in universities 
•Shell mode for experimentation 
•Awesome Excel integration

4. python functions