4. python functions

28
Functions

Upload: in4400

Post on 30-Jun-2015

90 views

Category:

Education


1 download

DESCRIPTION

Week 2

TRANSCRIPT

Page 1: 4. python   functions

Functions

Page 2: 4. python   functions
Page 3: 4. python   functions
Page 4: 4. python   functions

colon

start with ‘def’function name arguments

def twotimes(n):

return 2*n

‘return’ precedes

the value to be sent backNo declaration of types

of function or arguments

Page 5: 4. python   functions

New definition?

Page 6: 4. python   functions

New definition?

Page 7: 4. python   functions

New definition?

Page 8: 4. python   functions

Popquiz!

What happens now?

Page 9: 4. python   functions

Popquiz!

What happens now?

Page 10: 4. python   functions

No ‘overloading’

Page 11: 4. python   functions

More

functions

Page 12: 4. python   functions

What does this mean?

Page 13: 4. python   functions

Functions can be arguments

Page 14: 4. python   functions

Functions can be arguments

Page 15: 4. python   functions

We can also use an “anonymous function”

Page 16: 4. python   functions

Using

parameters

Page 17: 4. python   functions
Page 18: 4. python   functions
Page 19: 4. python   functions
Page 20: 4. python   functions
Page 21: 4. python   functions
Page 22: 4. python   functions
Page 23: 4. python   functions
Page 24: 4. python   functions
Page 25: 4. python   functions
Page 26: 4. python   functions
Page 27: 4. python   functions

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

Page 28: 4. python   functions

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