day2/cheatsheet3.tex
author Puneeth Chaganti <punchagan@fossee.in>
Sun, 10 Jan 2010 18:29:20 +0530
changeset 351 c9d1d5a7b629
parent 346 e9961fb16c58
child 354 5dc6c3673f9d
permissions -rw-r--r--
Edited import section in session3 - removed scipy imports.
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}
346
e9961fb16c58 Added package url to cheatsheets.
Puneeth Chaganti <punchagan@fossee.in>
parents: 330
diff changeset
    20
\usepackage{url}
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
    21
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
\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
    23
\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
    24
\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
    25
\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
    26
\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
    27
\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
    28
\end{center}
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    29
\section{Function}
329
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    30
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
    31
\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
    32
  \begin{lstlisting}
329
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    33
In []: def signum(r):
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    34
   ...:     if r < 0:
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    35
   ...:         return -1
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    36
   ...:     elif r > 0:
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    37
   ...:         return 1
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    38
   ...:     else:
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    39
   ...:         return 0
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    40
   ...:     
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    41
   ...:
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
    42
  \end{lstlisting}
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    43
%\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
    44
\subsection{Usage}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    45
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    46
In []: signum(4)
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    47
Out[]: 1
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    48
In []: signum(0)
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    49
Out[]: 0
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    50
In []: signum(-4)
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    51
Out[]: -1
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    52
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
    53
\end{lstlisting}
330
46533051b9d3 commited changes made for scipy and cheatsheats.
Shantanu <shantanu@fossee.in>
parents: 329
diff changeset
    54
\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, tuples), 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
    55
\subsection{Default Arguments}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    56
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
    57
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    58
In []: greet = 'hello world'
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    59
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    60
In []: greet.split()
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    61
Out[]: ['hello', 'world']
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    62
\end{lstlisting}
329
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
    63
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
    64
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    65
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
    66
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    67
In []: line.split(',') #split with ','
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    68
Out[]: ['Rossum', ' Guido', ' 54',
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    69
                        ' 46', ' 55']
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    70
\end{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    71
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
    72
\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
    73
def welcome(greet, name='world!'):
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    74
  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
    75
\end{lstlisting}
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    76
above function can be used as:
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    77
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    78
In []: welcome("Hello") #using default argument
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    79
Hello World!
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    80
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
    81
Hi Guido
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    82
\end{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    83
\subsection{Keyword Arguments}
330
46533051b9d3 commited changes made for scipy and cheatsheats.
Shantanu <shantanu@fossee.in>
parents: 329
diff changeset
    84
This feature provides the facility of passing arguments by specifying the name of the parameter as defined in the function definition. You don't 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
    85
\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
    86
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
    87
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
    88
\end{lstlisting}
330
46533051b9d3 commited changes made for scipy and cheatsheats.
Shantanu <shantanu@fossee.in>
parents: 329
diff changeset
    89
Both call to \typ{plot} function will work and parameters are set accordingly.\\
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    90
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
    91
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    92
def wish(name='World', greetings='Hello'):
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    93
  print greetings, name
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    94
\end{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    95
This function can be called as:
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    96
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    97
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
    98
Hello World
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
    99
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
   100
hey madhu
330
46533051b9d3 commited changes made for scipy and cheatsheats.
Shantanu <shantanu@fossee.in>
parents: 329
diff changeset
   101
In [15]: wish(name='vattam', greetings = 'bye bye')
46533051b9d3 commited changes made for scipy and cheatsheats.
Shantanu <shantanu@fossee.in>
parents: 329
diff changeset
   102
bye bye vattam
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   103
\end{lstlisting}
329
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
   104
% 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
   105
\section{Self contained python script}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   106
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
   107
  \begin{lstlisting}
351
c9d1d5a7b629 Edited import section in session3 - removed scipy imports.
Puneeth Chaganti <punchagan@fossee.in>
parents: 346
diff changeset
   108
from pylab import linspace, pi, sin
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
   109
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
   110
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
   111
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
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
   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, -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
   115
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
   116
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
   117
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
   118
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
   119
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
   120
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
   121
  \end{lstlisting}
329
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
   122
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
   123
\typ{$ python sine_plot.py} \\ %$ 
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
   124
We no longer need:
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   125
\begin{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   126
$ ipython -pylab
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   127
In []: %run -i sine_plot.py
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   128
\end{lstlisting} %$
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   129
\section{objects}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   130
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
   131
\begin{lstlisting}
329
0a6ab1d81491 Some more changes for day 2 sessions.
shantanu <shantanu@fossee.in>
parents: 327
diff changeset
   132
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
   133
In []: b = "Hello World"
330
46533051b9d3 commited changes made for scipy and cheatsheats.
Shantanu <shantanu@fossee.in>
parents: 329
diff changeset
   134
In []: b.split() # calling function on object 'b'
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   135
Out[]: ['Hello', 'World']
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   136
\end{lstlisting}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   137
``.'' 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
   138
\section{Links and References}
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   139
\begin{itemize}
330
46533051b9d3 commited changes made for scipy and cheatsheats.
Shantanu <shantanu@fossee.in>
parents: 329
diff changeset
   140
\item Some of inbuilt functions available with Python are listed at\\ \url{http://docs.python.org/library/functions.html}
327
c78cad28c2f7 modifeid cheat sheets for session 3, 4 day 2.
Shantanu <shantanu@fossee.in>
parents: 301
diff changeset
   141
\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
   142
\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
   143
\end{document}