• functions allow you to reuse the same piece of code
  • functions are defined with three components
    • header
      • includes the (def) keyword
      • the name of the function
      • and any parameters the function requires
    • optional comment
      • describes what the function does
    • body
      • describes the procedures the function carries out
      • indented
  • call and response
    • after defining a function it must be called to be implemented
      • def square(n)
      • square(10)
  • parameters and arguments
    • n is a parameter of square. a parameter acts as a variable name for a passed in argument. with the previous example, we called square with the argument 10. In this instance the function was called, n holds the value 10.
  • generic import: using a keyword to import a module
  • function import:
    • from math import sqrt
  • universal import: imports all functions of a module
    • from math import *
    • not a good idea to use
  • max() returns the largest number in the set
  • min() returns the smallest number
  • abs() absolute value, only takes one number
  • type() returns the type of data it receives
nov 29 2014 ∞
apr 19 2015 +