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 CS Majors Night What’s it like to be a CS major?
How do I declare a CS major? Find out Tonight! Rice 130 5pm

3 Questions?

4 Last Time Strings, casting types

5 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

6 Creating a function def name(“stuff we need to do the function”):
Indent Things we are doing return result

7 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

8 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

9 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