day1/session2.tex
author Puneeth Chaganti <punchagan@fossee.in>
Thu, 15 Oct 2009 18:46:40 +0530
changeset 129 d3aae4b05e99
parent 118 c7f85ba59af3
child 130 8905a5badd7e
permissions -rw-r--r--
Minor edits to day1 session1.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     2
%Tutorial slides on Python.
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     3
%
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     4
% Author: The FOSSEE Group
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     5
% Copyright (c) 2009, The FOSSEE Group, IIT Bombay
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     6
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     7
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     8
\documentclass[14pt,compress]{beamer}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     9
%\documentclass[draft]{beamer}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    10
%\documentclass[compress,handout]{beamer}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    11
%\usepackage{pgfpages} 
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    12
%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    13
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    14
% Modified from: generic-ornate-15min-45min.de.tex
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    15
\mode<presentation>
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    16
{
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    17
  \usetheme{Warsaw}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    18
  \useoutertheme{split}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    19
  \setbeamercovered{transparent}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    20
}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    21
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    22
\usepackage[english]{babel}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    23
\usepackage[latin1]{inputenc}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    24
%\usepackage{times}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    25
\usepackage[T1]{fontenc}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    26
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    27
% Taken from Fernando's slides.
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    28
\usepackage{ae,aecompl}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    29
\usepackage{mathpazo,courier,euler}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    30
\usepackage[scaled=.95]{helvet}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    31
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    32
\definecolor{darkgreen}{rgb}{0,0.5,0}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    33
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    34
\usepackage{listings}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    35
\lstset{language=Python,
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    36
    basicstyle=\ttfamily\bfseries,
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    37
    commentstyle=\color{red}\itshape,
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    38
  stringstyle=\color{darkgreen},
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    39
  showstringspaces=false,
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    40
  keywordstyle=\color{blue}\bfseries}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    41
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    42
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    43
% Macros
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    44
\setbeamercolor{emphbar}{bg=blue!20, fg=black}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    45
\newcommand{\emphbar}[1]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    46
{\begin{beamercolorbox}[rounded=true]{emphbar} 
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    47
      {#1}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    48
 \end{beamercolorbox}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    49
}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    50
\newcounter{time}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    51
\setcounter{time}{0}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    52
\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    53
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    54
\newcommand{\typ}[1]{\texttt{#1}}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    55
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    56
\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    57
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    58
%%% This is from Fernando's setup.
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    59
% \usepackage{color}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    60
% \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    61
% % Use and configure listings package for nicely formatted code
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    62
% \usepackage{listings}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    63
% \lstset{
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    64
%    language=Python,
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    65
%    basicstyle=\small\ttfamily,
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    66
%    commentstyle=\ttfamily\color{blue},
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    67
%    stringstyle=\ttfamily\color{orange},
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    68
%    showstringspaces=false,
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    69
%    breaklines=true,
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    70
%    postbreak = \space\dots
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    71
% }
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    72
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    73
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    74
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    75
% Title page
118
c7f85ba59af3 Added session4.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents: 109
diff changeset
    76
\title[Basic Python]{Python:Basic Overview\\}
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    77
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    78
\author[FOSEE Team] {The FOSSEE Group}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    79
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    80
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    81
\date[] {31, October 2009\\Day 1, Session 2}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    82
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    83
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    84
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    85
%\logo{\pgfuseimage{iitmlogo}}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    86
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    87
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    88
%% Delete this, if you do not want the table of contents to pop up at
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    89
%% the beginning of each subsection:
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    90
\AtBeginSubsection[]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    91
{
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    92
  \begin{frame}<beamer>
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    93
    \frametitle{Outline}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    94
    \tableofcontents[currentsection,currentsubsection]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    95
  \end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    96
}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    97
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    98
\AtBeginSection[]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    99
{
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   100
  \begin{frame}<beamer>
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   101
    \frametitle{Outline}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   102
    \tableofcontents[currentsection,currentsubsection]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   103
  \end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   104
}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   105
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   106
% If you wish to uncover everything in a step-wise fashion, uncomment
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   107
% the following command: 
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   108
%\beamerdefaultoverlayspecification{<+->}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   110
%\includeonlyframes{current,current1,current2,current3,current4,current5,current6}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   111
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   112
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   113
% DOCUMENT STARTS
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   114
\begin{document}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   115
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   116
\begin{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   117
  \titlepage
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   118
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   119
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   120
\begin{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   121
  \frametitle{Outline}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   122
  \tableofcontents
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   123
  % You might wish to add the option [pausesections]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   124
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   125
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   126
\section{Functions}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   127
\begin{frame}{Functions: Definition}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   128
\begin{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   129
  \item \kwrd{def} keyword
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   130
\end{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   131
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   132
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   133
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   134
\frametitle{Functions: Example 1}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   135
  \begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   136
In [1]: def plot_sinx():
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   137
   ....:     x = linspace(0, 2*pi, 100)
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   138
   ....:     plt.plot(x, sin(x))
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   139
   ....:     plt.show()
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   140
   ....:    
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   141
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   142
In [2]: plot_sinx()
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   143
  \end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   144
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   145
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   146
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   147
\frametitle{Functions: Example 2}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   148
  \begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   149
In [3]: def f(x):
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   150
   ....:     return sin(x*x*x)+(3*x*x)
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   151
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   152
In [4]: x = linspace(0,2*pi, 1000)
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   153
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   154
In [5]: plt.plot(x, f(x))
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   155
  \end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   156
  \inctime{10}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   157
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   158
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   159
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   160
% TIME: 10 m, running 
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   161
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   162
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   163
\section{Creating and running scripts}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   164
\begin{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   165
  {Creating python files}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   166
  \begin{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   167
    \item aka scripts
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   168
    \item use your editor
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   169
    \item extension \typ{.py}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   170
    \item run with \texttt{python hello.py} at the command line
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   171
    \item in IPython using \kwrd{\%run}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   172
  \end{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   173
\inctime{5}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   174
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   175
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   176
\section{Files Handling}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   177
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   178
  \frametitle{Basic File Operations}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   179
Opening and Reading files
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   180
\begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   181
In [6]: f = open('/path/to/file_name')
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   182
In [7]: data = f.read() # Read entire file.
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   183
In [8]: line = f.readline() # Read one line.
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   184
In [9]: f.close() # close the file.
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   185
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   186
Writing files
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   187
\begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   188
In [10]: f = open('/path/to/file_name', 'w')
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   189
In [11]: f.write('hello world\n')
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   190
In [12]: f.close()
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   191
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   192
\begin{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   193
    \item Everything read or written is a string
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   194
\end{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   195
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   196
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   197
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   198
    \frametitle{File and \kwrd{for}}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   199
\begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   200
In [13]: f = open('dummyfile')
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   201
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   202
In [14]: for line in f:
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   203
    ...:     print line
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   204
    ...:  
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   205
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   206
\inctime{10}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   207
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   208
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   209
\section{Strings}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   210
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   211
  \frametitle{Strings}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   212
  \begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   213
s = 'this is a string'
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   214
s = 'This one has "quotes" inside!'
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   215
s = "I have 'single-quotes' inside!"
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   216
l = "A string spanning many lines\
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   217
one more line\
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   218
yet another"
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   219
t = """A triple quoted string does
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   220
not need to be escaped at the end and 
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   221
"can have nested quotes" etc."""
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   222
  \end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   223
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   224
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   225
\begin{frame}[fragile]\frametitle{Strings and \typ{split()}}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   226
  \begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   227
In [15]: a = 'hello world'
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   228
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   229
In [16]: a.split()
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   230
Out[17]: ['hello', 'world']
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   231
  \end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   232
Now try this:
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   233
  \begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   234
In [18]: b = 'KD, Madhu, Punchagan, Shantanu, Vattam'
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   235
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   236
In [19]: b.split(',')
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   237
Out[20]: ['KD', ' Madhu', ' Punchagan', ' Shantanu', ' Vattam']
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   238
  \end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   239
\inctime{5}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   240
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   241
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   242
\section{Plotting points}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   243
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   244
\frametitle{How to plot points?}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   245
We saw how to plot graphs, lets now look at how to plot points.\\
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   246
\begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   247
In [21]: plt.plot(x, sin(x), 'ro')
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   248
Out[22]: [<matplotlib.lines.Line2D object at 0xac17e0c>]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   249
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   250
\begin{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   251
  \item \kwrd{'r'},\kwrd{'g'},\kwrd{'b'} for red, green and blue
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   252
  \item \kwrd{'o'} - Dots
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   253
  \item \kwrd{'-'} - Lines
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   254
  \item \kwrd{'- -'} - Dashed lines
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   255
\end{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   256
\inctime{5}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   257
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   258
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   259
\section{Lists}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   260
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   261
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   262
  \frametitle{List creation and indexing}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   263
\begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   264
In [23]: lst = [] #Empty list
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   265
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   266
In [24]: lst = [1,2,3,4] #More useful list
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   267
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   268
In [25]: len(lst)
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   269
Out[26]: 4
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   270
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   271
In [27]: lst[0]+lst[1]+lst[-1]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   272
Out[27]: 7
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   273
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   274
\begin{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   275
  \item Indices start with ?
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   276
  \item Negative indices indicate ?
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   277
  \end{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   278
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   279
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   280
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   281
  \frametitle{List: slices}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   282
  \begin{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   283
  \item Slicing is a basic operation
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   284
  \item \typ{list[initial:final:step]}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   285
  \item  The step is optional
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   286
  \end{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   287
\begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   288
In [28]: lst[1:3]  # A slice.
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   289
Out[28]: [2, 3]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   290
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   291
In [29]: lst[1:-1]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   292
Out[29]: [2, 3]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   293
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   294
In [30]: lst[1:] == lst[1:-1]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   295
Out[30]: False
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   296
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   297
Explain last result
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   298
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   299
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   300
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   301
  \frametitle{List: more slices}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   302
\begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   303
In [31]: lst[0:-1:2] # Notice the step!
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   304
Out[31]: [1, 3]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   305
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   306
In [31]: lst[::2]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   307
Out[31]: [1, 3]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   308
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   309
In [32]: lst[-1::-1]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   310
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   311
What do you think the last one will do?
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   312
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   313
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   314
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   315
  \frametitle{List methods}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   316
\begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   317
In [33]: lst.append(5)
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   318
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   319
In [34]: lst
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   320
Out[34]: [1, 2, 3, 4, 5]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   321
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   322
In [35]: lst.append([6,7])
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   323
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   324
In [36]: lst
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   325
Out[36]: [1, 2, 3, 4, 5, [6, 7]]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   326
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   327
In [37]: lst.extend([8,9])
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   328
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   329
In [38]: lst
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   330
Out[38]: [1, 2, 3, 4, 5, [6, 7], 8, 9]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   331
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   332
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   333
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   334
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   335
  \frametitle{List containership}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   336
  \begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   337
In [39]: animals = ['cat', 'dog', 'rat', 'croc']
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   338
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   339
In [40]: 'dog' in animals
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   340
Out[40]: True
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   341
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   342
In [41]: 'snake' in animals
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   343
Out[41]: False
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   344
  \end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   345
  \inctime{10}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   346
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   347
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   348
\section{Modules and import}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   349
\begin{frame}{Modules and \typ{import}}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   350
  \begin{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   351
    \item \kwrd{import} x
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   352
    \item \kwrd{from} x \kwrd{import} y
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   353
  \end{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   354
Whats the difference??
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   355
\inctime{5}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   356
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   357
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   358
\end{document}