functions.org
changeset 118 2f247bcfae8b
parent 113 6388eacf7502
child 119 7dc53e6c8065
equal deleted inserted replaced
117:d3005da44457 118:2f247bcfae8b
    87     keyword arguments. We can call the function in a variety of ways.
    87     keyword arguments. We can call the function in a variety of ways.
    88         welcome("Hello", "James")
    88         welcome("Hello", "James")
    89 	welcome("Hi", name="Guido")
    89 	welcome("Hi", name="Guido")
    90 	welcome(name="Guido", greet="Hello")
    90 	welcome(name="Guido", greet="Hello")
    91 
    91 
    92     Keyword arguments allow us to call functions by passing arguments
    92     Keyword arguments allow us to call functions by passing arguments 
    93     in any order and removes need to remember the order of arguments
    93     in any order and removes need to remember the order of arguments
    94     in the function definition. 
    94     in the function definition. 
       
    95  
       
    96     Let us look at an example function. This will both act as a code
       
    97     reading exercise and tell us an important point about return
       
    98     values in python's functions. Pause the video for a while and
       
    99     ponder about what this piece of code does. 
       
   100     [show slide?]
    95 
   101 
       
   102     def what( n ):
       
   103         i = 1
       
   104 	while i * i < n:
       
   105   	    i += 1
       
   106 	return i * i == n, i
    96 
   107 
    97 ***** return values
   108     The function takes an integer as an argument and returns the
       
   109     boolean True, and the square of the number, if it is a perfect
       
   110     square OR the boolean False and the square root of the next
       
   111     perfect square of the number. 
       
   112     Note that this function is returning two values. Functions in
       
   113     Python are capable of returning any number of values. 
       
   114 
    98 ***** arguments are local to a function
   115 ***** arguments are local to a function
    99 ***** availability library functions
   116 
   100 ***** code reading exercises?
   117     Python follows the philosophy of batteries included. It comes
   101   
   118     with a rich and versatile standard library with whole gamut of
       
   119     functions. Do check out the standard library, before you sit down
       
   120     to write functions of your own. 
       
   121 
   102     We come to the end of this tutorial on functions. In this tutorial
   122     We come to the end of this tutorial on functions. In this tutorial
   103     we have learnt about functions in a greater detail. We looked at
   123     we have learnt about functions in a greater detail. We looked at
   104     how to define functions, calling them, default and keyword
   124     how to define functions, calling them, default and keyword
   105     arguments. 
   125     arguments. 
   106 
   126