author | amit |
Wed, 13 Oct 2010 17:28:04 +0530 | |
changeset 322 | 3cacbcad4c42 |
parent 217 | b595f90016c5 |
child 240 | f4c36aa38a84 |
permissions | -rw-r--r-- |
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
1 |
======== |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
2 |
Script |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
3 |
======== |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
4 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
5 |
{{{ show the welcome slide }}} |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
6 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
7 |
Welcome to the tutorial on advanced feature of functions. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
8 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
9 |
{{{ show the outline slide }}} |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
10 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
11 |
In this tutorial we shall be looking at specifying default arguments |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
12 |
to functions when defining them and calling functions using keyword |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
13 |
arguments. We shall also, look at some of the built-in functions |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
14 |
available in the standard library of Python. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
15 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
16 |
{{{ switch to terminal }}} |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
17 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
18 |
We have an ``ipython`` terminal open, which we shall be using through |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
19 |
out this session. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
20 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
21 |
Let's use the ``round`` function as an example to understand what a |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
22 |
default value of an argument means. Let's type the following |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
23 |
expressions in the terminal. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
24 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
25 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
26 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
27 |
round(2.484) |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
28 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
29 |
round(2.484, 2) |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
30 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
31 |
Both the first expression and the second are calls to the ``round`` |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
32 |
function, but the first calls it with only one argument and the second |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
33 |
calls it with two arguments. By observing the output, we can guess |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
34 |
that the first one is equivalent to call with the second argument |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
35 |
being 0. 0 is the default value of the argument. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
36 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
37 |
{{{ show a slide with examples of functions showing default values }}} |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
38 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
39 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
40 |
s.strip() # strips on spaces. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
41 |
s.strip('@') # strips the string of '@' symbols. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
42 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
43 |
plot(x, y) # plots with x vs. y using default line style. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
44 |
plot(x, y, 'o') # plots x vs. y with circle markers. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
45 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
46 |
linspace(0, 2*pi, 100) # returns 100 points between 0 and 2pi |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
47 |
linspace(0, 2*pi) # returns 50 points between 0 and 2pi |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
48 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
49 |
#[punch: all above content goes on to a slide] |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
50 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
51 |
{{{ switch back to ipython }}} |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
52 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
53 |
Let's now define a simple function that uses default arguments. We |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
54 |
define a simple function that prints a welcome message to a person, |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
55 |
given a greeting and his/her name. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
56 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
57 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
58 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
59 |
def welcome(greet, name="World"): |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
60 |
print greet, name |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
61 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
62 |
Let us first call the function with two arguments, one for ``greet`` |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
63 |
and other for ``name``. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
64 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
65 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
66 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
67 |
welcome("Hi", "Guido") |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
68 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
69 |
We get the expected welcome message, "Hi Guido". |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
70 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
71 |
Now let us call the function with just one argument "Hello". |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
72 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
73 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
74 |
welcome("Hello") |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
75 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
76 |
"Hello" is treated as the ``greet`` and we get "Hello World" as |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
77 |
the output. "World" is the default value for the argument ``name``. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
78 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
79 |
E%% %% Pause the video here and redefine the function ``welcome``, by |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
80 |
interchanging it's arguments. Place the ``name`` argument with it's |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
81 |
default value of "Hello" before the ``greet`` argument. Then, resume |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
82 |
the video. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
83 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
84 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
85 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
86 |
def welcome(name="World", greet): |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
87 |
print greet, name |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
88 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
89 |
We get an error that reads ``SyntaxError: non-default argument follows |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
90 |
default argument``. When defining a function all the argument with |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
91 |
default values should come at the end. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
92 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
93 |
E%% %% Pause the video here and type ``linspace?`` to see the |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
94 |
definition of the command and notice how all the arguments with |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
95 |
default values are towards the end. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
96 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
97 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
98 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
99 |
linspace? |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
100 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
101 |
E%% %% Pause the video here and redefine the function ``welcome`` with |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
102 |
a default value of "Hello" to the ``greet`` argument. Then, call the |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
103 |
function without any arguments. Then, resume the video. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
104 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
105 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
106 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
107 |
def welcome(greet="Hello", name="World"): |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
108 |
print greet, name |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
109 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
110 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
111 |
welcome() |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
112 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
113 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
114 |
Let us now learn what keyword arguments are. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
115 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
116 |
{{{ show a slide with examples using keyword arguments. }}} |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
117 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
118 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
119 |
legend(['sin(2y)'], loc = 'center') |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
120 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
121 |
plot(y, sin(y), 'g', linewidth = 2) |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
122 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
123 |
annotate('local max', xy = (1.5, 1)) |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
124 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
125 |
pie(science.values(), labels = science.keys()) |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
126 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
127 |
When you are calling functions in Python, you don't need to remember |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
128 |
the order in which to pass the arguments. Instead, you can use the |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
129 |
name of the argument to pass it a value. This slide shows a few |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
130 |
function calls that use keyword arguments. ``loc``, ``linewidth``, |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
131 |
``xy`` and ``labels`` are being called with keyword arguments. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
132 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
133 |
{{{ switch to ipython terminal }}} |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
134 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
135 |
Let us try and understand this better using the ``welcome`` function |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
136 |
that we have been using all along. Let us call it in different ways |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
137 |
and observe the output to see how keyword arguments work. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
138 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
139 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
140 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
141 |
welcome() |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
142 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
143 |
welcome("Hello", "James") |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
144 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
145 |
welcome("Hi", name="Guido") |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
146 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
147 |
When no keyword is specified, the arguments are allotted based on |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
148 |
their position. So, "Hi" is the value of the argument ``greet`` and |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
149 |
name is passed the value "Guido". |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
150 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
151 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
152 |
welcome(name="Guido", greet="Hey! ") |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
153 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
154 |
When keyword arguments are used, the arguments can be called in any |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
155 |
order. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
156 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
157 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
158 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
159 |
welcome(name="Guido", "Hey") |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
160 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
161 |
This call returns an error that reads, ``non keyword arg after keyword |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
162 |
arg``. Python expects all the keyword to be present towards the end. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
163 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
164 |
That brings us to the end of what we wanted to learn about ``keyword`` |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
165 |
arguments. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
166 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
167 |
{{{ switch to a slide showing variety of functions with uses }}} |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
168 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
169 |
Before defining a function of your own, make sure that you check the |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
170 |
standard library, for a similar function. Python is popularly called a |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
171 |
"Batteries included" language, for the huge library that comes along |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
172 |
with it. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
173 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
174 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
175 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
176 |
Math functions - abs, sin, .... |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
177 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
178 |
#[punch: Need to decide, exactly what to put here. Reviewer comments |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
179 |
welcome.] |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
180 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
181 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
182 |
{{{ switch to slide showing classes of functions in pylab, scipy }}} |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
183 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
184 |
Apart from the standard library there are other libraries like ``pylab``, |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
185 |
``scipy``, etc which have a huge collection of functions for scientific |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
186 |
purposes. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
187 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
188 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
189 |
pylab |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
190 |
plot, bar, contour, boxplot, errorbar, log, polar, quiver, semilog |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
191 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
192 |
scipy (modules) |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
193 |
fftpack, stats, linalg, ndimage, signal, optimize, integrate |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
194 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
195 |
{{{ switch slide to summary slide }}} |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
196 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
197 |
That brings us to the end of this tutorial. In this tutorial we have |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
198 |
learnt how to use functions with default values and keyword |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
199 |
arguments. We also looked at the range of functions available in the |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
200 |
Python standard library and the Scientific Computing related |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
201 |
packages. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
202 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
203 |
Thank You! |