Sunday, January 20, 2013

How to Function

Functions in python are similar to functions in Jeroo. They are defined by the word def followed by the name and then the arguments
ex. def myster(a,b):
Anything included in the function must be written after the definition and indented and when functions are to be used, they need to be called and the call needs to follow the same indention as the definition. Arguments within the call must also be written out
ex myster(a,b)
Regardless of how you define a variable before a function, variables are bound at the call site. In other words, previous variables are forgotten. In the words of the powerpoint "Variables used in functions but defined outside of the function can be changed"

So why you functions or what can you do with functions?
1. they can make code easier
2.they can be used to define local variables (a. a new variable altogether or b. redefining a variable previously defined outside of the function to substitute its value)* these variables are then bound or set within the function
3.define new functions (act as a stepping stone for another function. similar to nesting?)

Lab issues:
So, this week's lab. I gotta say, it wasn't the most straightforward to say the least but i think next time i should open two skeleton documents, get rid of all the notes in one and work on that in order to mitigate any confusion that comes from the text....hopefully the i can focus better on the task. In general, although i feel like i understand functions, i still need to practice more so that defining variables will become more like second nature...maybe tomorrow...maybe : )

No comments:

Post a Comment