day2/cheatsheet3.tex
author shantanu <shantanu@fossee.in>
Tue, 08 Dec 2009 13:06:14 +0530
changeset 329 0a6ab1d81491
parent 327 c78cad28c2f7
child 330 46533051b9d3
permissions -rw-r--r--
Some more changes for day 2 sessions.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
301
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     1
\documentclass[12pt]{article}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     2
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     3
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     4
\title{Python: Data Structures}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     5
\author{FOSSEE}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     6
\usepackage{listings}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     7
\lstset{language=Python,
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     8
    basicstyle=\ttfamily,
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     9
commentstyle=\itshape\bfseries, 
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    10
showstringspaces=false
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    11
}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    12
\newcommand{\typ}[1]{\lstinline{#1}}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    13
\usepackage[english]{babel}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    14
\usepackage[latin1]{inputenc}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    15
\usepackage{times}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    16
\usepackage[T1]{fontenc}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    17
\usepackage{ae,aecompl}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    18
\usepackage{mathpazo,courier,euler}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    19
\usepackage[scaled=.95]{helvet}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    20
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    21
\begin{document}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    22
\date{}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    23
\vspace{-1in}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    24
\begin{center}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    25
\LARGE{Python: Functions and Objects}\\
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    26
\large{FOSSEE}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    27
\end{center}
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    28
\section{Function}
329
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    29
They allows us to enclose a set of statements and call them again and again instead of repeating the group of statements every-time. 
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    30
\subsection{Function definition}
301
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    31
  \begin{lstlisting}
329
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    32
In []: def signum(r):
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    33
   ...:     if r < 0:
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    34
   ...:         return -1
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    35
   ...:     elif r > 0:
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    36
   ...:         return 1
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    37
   ...:     else:
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    38
   ...:         return 0
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    39
   ...:     
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    40
   ...:
301
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    41
  \end{lstlisting}
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    42
%\typ{def} is a keyword, which is used to define a function with given name.
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    43
\subsection{Usage}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    44
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    45
In []: signum(4)
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    46
Out[]: 1
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    47
In []: signum(0)
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    48
Out[]: 0
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    49
In []: signum(-4)
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    50
Out[]: -1
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    51
In []: signum() # ERROR signum() takes exactly 1 argument(0 given)
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    52
\end{lstlisting}
329
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    53
\textbf{Note:} Arguments passed to a function are passed by-value \textbf{only if} they are basic Python data type(int, float). In case one passes immutable types(String, tupels), they cant be modified in the function, but objects like \typ{list} and dictionary can be manipulated.
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    54
\subsection{Default Arguments}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    55
This feature allow the functions to take the arguments optionally. For example:
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    56
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    57
In []: greet = 'hello world'
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    58
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    59
In []: greet.split()
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    60
Out[]: ['hello', 'world']
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    61
\end{lstlisting}
329
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    62
In above case, default argument which \typ{split} function uses is a blank space. One can pass argument also to split the string for a different delimiter.
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    63
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    64
In []: line = 'Rossum, Guido, 54, 46, 55'
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    65
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    66
In []: line.split(',') #split with ','
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    67
Out[]: ['Rossum', ' Guido', ' 54',
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    68
                        ' 46', ' 55']
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    69
\end{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    70
Function to work with default argument can be defined as:
301
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    71
\begin{lstlisting}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    72
def welcome(greet, name='world!'):
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    73
  print greet, name
301
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    74
\end{lstlisting}
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    75
above function can be used as:
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    76
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    77
In []: welcome("Hello") #using default argument
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    78
Hello World!
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    79
In []: welcome("Hi", "Guido") #taking name via argument
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    80
Hi Guido
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    81
\end{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    82
\subsection{Keyword Arguments}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    83
This feature provides the facility of passing arguments by specifying the name of the parameter as defined in the function definition. You dont have to remember the order of the parameters in function definition. For example:
301
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    84
\begin{lstlisting}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    85
In []: plot(y, sin(y), 'g', linewidth=2)
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    86
In []: plot(y, cos(y), linewidth=1, color='g')
301
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    87
\end{lstlisting}
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    88
Both call to \typ{plot} function will work and paramenters are set accordingly.\\
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    89
One can define a function such that keyword arguments can be used in following way:
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    90
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    91
def wish(name='World', greetings='Hello'):
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    92
  print greetings, name
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    93
\end{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    94
This function can be called as:
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    95
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    96
In [13]: wish() #default arguments will work
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    97
Hello World
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    98
In [14]: wish(greetings='hey', name='madhu')
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    99
hey madhu
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   100
In [15]: wish(name='vattam', greetings = 'get lost')
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   101
get lost vattam
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   102
\end{lstlisting}
329
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
   103
% sorry Vattam just a joke :P
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   104
\section{Self contained python script}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   105
Functions like \typ{plot}, \typ{linspace} etc are not inbuilt functions. One have to import them to use them.
301
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   106
  \begin{lstlisting}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   107
from scipy import linspace, pi, sin
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   108
from pylab import plot, legend, annotate
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   109
from pylab import xlim, ylim
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   110
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   111
x = linspace(-5*pi, 5*pi, 500)
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   112
plot(x, x, 'b')
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   113
plot(x, -x, 'b')
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   114
plot(x, sin(x), 'g', linewidth=2)
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   115
plot(x, x*sin(x), 'r', linewidth=3)
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   116
legend(['x', '-x', 'sin(x)', 'xsin(x)'])
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   117
annotate('origin', xy = (0, 0))
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   118
xlim(-5*pi, 5*pi)
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   119
ylim(-5*pi, 5*pi)
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   120
  \end{lstlisting}
329
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
   121
These import statements are necessary to make program self contained. After importing, we can run script via:\\
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
   122
\typ{$ python sine_plot.py} \\ %$ 
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
   123
We no longer need:
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   124
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   125
$ ipython -pylab
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   126
In []: %run -i sine_plot.py
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   127
\end{lstlisting} %$
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   128
\section{objects}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   129
In Python everything is a object! All variables, lists, tuples, dictionaries and even functions are objects. 
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   130
\begin{lstlisting}
329
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
   131
In []: a = str() # initializing a string object.
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   132
In []: b = "Hello World"
329
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
   133
In []: b.split() # calling funciton on object 'b'
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   134
Out[]: ['Hello', 'World']
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   135
\end{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   136
``.'' is a operator used to call functions defined for given object.
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   137
\section{Links and References}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   138
\begin{itemize}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   139
\item Some of inbult functions available with Python are listed at\\ \url{http://docs.python.org/library/functions.html}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   140
\item Reference manual to describe the standard libraries  that are distributed with Python is available at \url{http://docs.python.org/library/} 
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   141
\end{itemize}
301
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   142
\end{document}