Functions

Lesson

What is a function?

  • range() and len() are functions!
  • These have pre-defined behavior
  • Allow you to input something then return something
  • Example: range takes 1 or 2 numbers as input then returns a list

How do we create one?

  • Line 1: def {functionName} ({inputs}):
  • Line 2+: tab, then operations to perform
  • (optional) last line: return 1+ variables!
  • Use function using its name and passing in the inputs you defined

Function options

  • You can introduce optional inputs/arguments (see Playground for example)
  • Use as many inputs and outputs as you need, just remember order is important!

Playground