FunctionsThe def statement# Return the remainder of a/b def remainder(a,b): q = a/b r = a - q*b return r # Now use it a = remainder(42,5) # a = 2 Returning multiple valuesdef divide(a,b): q = a/b r = a - q*b return q,r x,y = divide(42,5) # x = 8, y = 2 |
<<< | O'Reilly OSCON 2000, Advanced Python Programming, Slide 15 July 17, 2000, beazley@cs.uchicago.edu |
>>> |