Presentation is loading. Please wait.

Presentation is loading. Please wait.

Nate Brunelle Today: Functions

Similar presentations


Presentation on theme: "Nate Brunelle Today: Functions"— Presentation transcript:

1 Nate Brunelle Today: Functions
CS1110 Nate Brunelle Today: Functions

2 Questions?

3 Last Time Strings, casting types

4 Function Like going to chipotle:
Enter with Your chipotle order in mind Input Instructions for how to turn your order into a burrito Things can happen at chipotle that leave chipotle Side effects E.g. less money in your bank account Leave with your burrito/bowl output

5 Creating a function def name(input(s)): Things we are doing
Indent Things we are doing return output

6 Functions Vocab Expression – Code that can become a value
Literal expression – an expression that cannot be simplified Evaluate – turn an expression into a value Argument – value/expression we send into a function Parameter – name we use for input within a function definition Attached to an argument when we use the function Call/invoke – Use a function Return – exit the function with a value Return Value – the value we returned Side Effect – things that a function does beyond returning something

7 Advice on functions You usually don’t want functions with side effects
Don’t use print, instead return a str Don’t use input, instead use parameters Good names Usually an action phrase Use docstrings Define function in one file, use in another

8 Scope Scope- The are where a variable has meaning
Usually: variable is in scope when it is created onward. Functions: variable is in scope when it is created until end of the function definition


Download ppt "Nate Brunelle Today: Functions"

Similar presentations


Ads by Google