Functions Revisited

def statement

  • Defines a new function
     def fname(args):
          statements
  • Example:
     def divide(a,b):
         return a/b 

Calling a function

     x = divide(7,3) 

Calling a function with keyword arguments

     x = divide(b=3, a=7) 
  • Exact same result as before, argument names specified explicitly.
<<< O'Reilly OSCON 2000, Introduction to Python, Slide 79
July 17, 2000, beazley@cs.uchicago.edu
>>>