day2/cheatsheet3.tex
author Shantanu <shantanu@fossee.in>
Wed, 25 Nov 2009 12:11:03 +0530
changeset 327 c78cad28c2f7
parent 301 49bdffe4dca5
child 329 0a6ab1d81491
permissions -rw-r--r--
modifeid cheat sheets for session 3, 4 day 2.
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}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    29
They allows us to enclose a set of statements and call the function again and again instead of repeating the group of statements every-time. 
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}
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    32
def signum( r ):    
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    33
    if r < 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
    34
        return -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
    35
    elif r > 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
    36
        return 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
    37
    else:
49bdffe4dca5 Updated session 2 slides of day 1 and added cheatsheets of day 2.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    38
        return 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
    39
  \end{lstlisting}
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    40
%\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
    41
\subsection{Usage}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    42
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    43
In []: signum(4)
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    44
Out[]: 1
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    45
In []: signum(0)
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    46
Out[]: 0
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    47
In []: signum(-4)
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    48
Out[]: -1
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    49
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
    50
\end{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    51
\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 pass immutable types(String, tupels), they cant be modified in the function, but objects like \typ{list} and dictionary can be manipulated.
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    52
\subsection{Default Arguments}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    53
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
    54
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    55
In []: greet = 'hello world'
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    56
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    57
In []: greet.split()
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    58
Out[]: ['hello', 'world']
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    59
\end{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    60
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.
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    61
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    62
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
    63
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    64
In []: line.split(',') #split with ','
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    65
Out[]: ['Rossum', ' Guido', ' 54',
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    66
                        ' 46', ' 55']
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    67
\end{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    68
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
    69
\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
    70
def welcome(greet, name='world!'):
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    71
  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
    72
\end{lstlisting}
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    73
above function can be used as:
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    74
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    75
In []: welcome("Hello") #using default argument
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    76
Hello World!
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    77
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
    78
Hi Guido
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    79
\end{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    80
\subsection{Keyword Arguments}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    81
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
    82
\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
    83
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
    84
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
    85
\end{lstlisting}
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    86
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
    87
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
    88
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    89
def wish(name='World', greetings='Hello'):
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    90
  print greetings, name
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    91
\end{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    92
This function can be called as:
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    93
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    94
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
    95
Hello World
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    96
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
    97
hey madhu
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    98
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
    99
get lost vattam
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   100
\end{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   101
\section{Self contained python script}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   102
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
   103
  \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
   104
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
   105
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
   106
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
   107
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
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
   109
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
   110
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
   111
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
   112
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
   113
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
   114
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
   115
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
   116
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
   117
  \end{lstlisting}
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   118
Above mentioned code will work with following setup:
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   119
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   120
$ ipython -pylab
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   121
In []: %run -i sine_plot.py
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   122
\end{lstlisting} %$
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   123
as we are already including \typ{pylab} into \typ{ipython}. But to make it work independently so that even\\
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   124
\typ{$ python sine_plot.py} \\ %$ 
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   125
works, one will have to use \typ{import} statements.\\
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   126
\section{objects}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   127
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
   128
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   129
In []: a = str() 
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   130
In []: b = "Hello World"
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   131
In []: b.split()
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   132
Out[]: ['Hello', 'World']
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   133
\end{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   134
``.'' 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
   135
\section{Links and References}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   136
\begin{itemize}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   137
\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
   138
\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
   139
\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
   140
\end{document}