advanced-features-functions/slides.org
author Nishanth <nishanth@fossee.in>
Mon, 11 Oct 2010 23:36:15 +0530
changeset 303 56dc2183f1de
parent 272 08638b1e211e
permissions -rw-r--r--
Merged
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
272
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     1
#+LaTeX_CLASS: beamer
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     2
#+LaTeX_CLASS_OPTIONS: [presentation]
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     3
#+BEAMER_FRAME_LEVEL: 1
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     4
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     5
#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     6
#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     7
#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     8
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     9
#+LaTeX_CLASS: beamer
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    10
#+LaTeX_CLASS_OPTIONS: [presentation]
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    11
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    12
#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    13
#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    14
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    15
#+LaTeX_HEADER: \usepackage{listings}
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    16
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    17
#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    18
#+LaTeX_HEADER:  commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    19
#+LaTeX_HEADER:  showstringspaces=false, keywordstyle=\color{blue}\bfseries}
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    20
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    21
#+TITLE:    Advanced features of functions
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    22
#+AUTHOR:    FOSSEE
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    23
#+EMAIL:     
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    24
#+DATE:    
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    25
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    26
#+DESCRIPTION: 
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    27
#+KEYWORDS: 
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    28
#+LANGUAGE:  en
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    29
#+OPTIONS:   H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    30
#+OPTIONS:   TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    31
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    32
* Outline
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    33
  - Assigning default values to arguments
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    34
  - Calling functions using Keyword arguments
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    35
  - functions in standard library 
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    36
* Question 1
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    37
  Redefine the function ~welcome~, by interchanging it's
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    38
  arguments. Place the ~name~ argument with it's default value of
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    39
  "World" before the ~greet~ argument.
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    40
* Solution 1
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    41
  #+begin_src python
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    42
    def welcome(name="World", greet):
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    43
        print greet, name
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    44
  #+end_src
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    45
  We get an error that reads ~SyntaxError: non-default argument
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    46
  follows default argument~. When defining a function all the
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    47
  argument with default values should come at the end.
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    48
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    49
* Question 2
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    50
  See the definition of linspace using ~?~ and observe how all the
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    51
  arguments with default values are towards the end.
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    52
* Solution 2
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    53
  #+begin_src python
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    54
    linspace?
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    55
  #+end_src
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    56
* Question 3
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    57
  Redefine the function ~welcome~ with a default value of
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    58
  "Hello" to the ~greet~ argument. Then, call the function without any
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    59
  arguments. 
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    60
* Solution 3
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    61
  #+begin_src python
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    62
    def welcome(greet="Hello", name="World"):
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    63
        print greet, name
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    64
     
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    65
    welcome()
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    66
  #+end_src
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    67
* Summary
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    68
  You should now be able to --
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    69
  + define functions with default arguments
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    70
  + call functions using keyword arguments
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    71
* Thank you!
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    72
#+begin_latex
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    73
  \begin{block}{}
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    74
  \begin{center}
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    75
  This spoken tutorial has been produced by the
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    76
  \textcolor{blue}{FOSSEE} team, which is funded by the 
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    77
  \end{center}
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    78
  \begin{center}
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    79
    \textcolor{blue}{National Mission on Education through \\
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    80
      Information \& Communication Technology \\ 
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    81
      MHRD, Govt. of India}.
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    82
  \end{center}  
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    83
  \end{block}
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    84
#+end_latex
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    85
08638b1e211e Slides for advanced features of functions LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    86