# HG changeset patch # User asokan # Date 1274177417 -19800 # Node ID 2eac725a57663f408cd18346f30bdf82f556e1f1 # Parent 27ddf1255daa03854828d5bc14d51f743f6ea830# Parent 67c4a2c75aee511c7821cb31778b95bcb42f0069 changes to array.txt diff -r 27ddf1255daa -r 2eac725a5766 functions.org --- a/functions.org Tue May 18 15:27:02 2010 +0530 +++ b/functions.org Tue May 18 15:40:17 2010 +0530 @@ -22,17 +22,19 @@ equations. We shall first review these basics. Then we shall move on to other details such as doc-strings, default arguments and keyword arguments. + + First let's start IPython by typing ipython in the terminal. - Let's write a simple function that prints a Hello message, after + Let's write a simple function that prints a Hello message, upon accepting a name. def welcome(name): print "Hello", name - You would recall that def is a keyword that indicates a function + You would recall that def is a keyword that indicates the function definition. 'welcome' is the name of the function and 'name' is the lone argument to the function. Note that the function is - defined within an indented block, similar to any other block. Our + defined within an indented block, just like to any other block. Our function welcome just has one line in it's definition. We can call our function, as follows - @@ -55,7 +57,10 @@ Notice that the doc string uses triple quotes. If the doc-string exceeds one line, we can use new line characters in it. Also, as expected the doc-string is indented as is required - for anything within a block. + for anything within a block. Now that we have written the + documentation, how do we access it? IPython provides the question + mark feature that we have seen in the previous tutorials. welcome? + will display the docstring that we have just written. We shall now look at default arguments. [show slide with examples of functions with default arguments] diff -r 27ddf1255daa -r 2eac725a5766 functions_.txt --- a/functions_.txt Tue May 18 15:27:02 2010 +0530 +++ b/functions_.txt Tue May 18 15:40:17 2010 +0530 @@ -9,5 +9,5 @@ We have given the function the name signum . Essentially what it does is that based on whether the no is 0 , negative or positive , it returns 0 , -1 and +1 respectively . In this case it recieves value of the no in variable r . -In the beginning of the function you can see a triple quoted string . This is called a docstring . You can write some documentation related to your function. In this you can have the function parameters and what it returns . A python function returns a value by using the keyword return . +In the beginning of the function you can see a triple quoted string . This is called a docstring. You can write some documentation related to your function. In this you can have the function parameters and what it returns. A python function returns a value by using the keyword return.