4. python functions
DESCRIPTION
Week 2TRANSCRIPT
![Page 1: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/1.jpg)
Functions
![Page 2: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/2.jpg)
![Page 3: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/3.jpg)
![Page 4: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/4.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/5.jpg)
New definition?
![Page 6: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/6.jpg)
New definition?
![Page 7: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/7.jpg)
New definition?
![Page 8: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/8.jpg)
Popquiz!
What happens now?
![Page 9: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/9.jpg)
Popquiz!
What happens now?
![Page 10: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/10.jpg)
No ‘overloading’
![Page 11: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/11.jpg)
More
functions
![Page 12: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/12.jpg)
What does this mean?
![Page 13: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/13.jpg)
Functions can be arguments
![Page 14: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/14.jpg)
Functions can be arguments
![Page 15: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/15.jpg)
We can also use an “anonymous function”
![Page 16: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/16.jpg)
Using
parameters
![Page 17: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/17.jpg)
![Page 18: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/18.jpg)
![Page 19: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/19.jpg)
![Page 20: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/20.jpg)
![Page 21: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/21.jpg)
![Page 22: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/22.jpg)
![Page 23: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/23.jpg)
![Page 24: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/24.jpg)
![Page 25: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/25.jpg)
![Page 26: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/26.jpg)
![Page 27: 4. python functions](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/27.jpg)
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](https://reader034.vdocuments.us/reader034/viewer/2022042614/5592393d1a28ab075d8b45b1/html5/thumbnails/28.jpg)
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