day1/session2.tex
author Santosh G. Vattam <vattam.santosh@gmail.com>
Tue, 13 Oct 2009 16:40:05 +0530
changeset 109 16e04782baac
child 118 c7f85ba59af3
permissions -rw-r--r--
Added session2.tex.
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
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    76
\title[Basic Python]{Python:\\A great programming toolkit}
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
\begin{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   120
  {Acknowledgements}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   121
  \begin{center}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   122
  This program is conducted by\\
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   123
  IIT, Bombay\\
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   124
  as part of  the open source initiatives\\
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   125
  under the aegis of\\
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   126
  \alert{National Mission on Education through ICT,} \\
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   127
  Ministry of HRD.
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   128
  \end{center}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   129
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   130
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   131
\begin{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   132
  \frametitle{Outline}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   133
  \tableofcontents
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   134
  % You might wish to add the option [pausesections]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   135
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   136
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   137
\section{Functions}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   138
\begin{frame}{Functions: Definition}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   139
\begin{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   140
  \item \kwrd{def} keyword
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   141
\end{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   142
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   143
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   144
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   145
\frametitle{Functions: Example 1}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   146
  \begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   147
In [1]: def plot_sinx():
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   148
   ....:     x = linspace(0, 2*pi, 100)
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   149
   ....:     plt.plot(x, sin(x))
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   150
   ....:     plt.show()
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
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   153
In [2]: plot_sinx()
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   154
  \end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   155
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   156
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   157
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   158
\frametitle{Functions: Example 2}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   159
  \begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   160
In [3]: def f(x):
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   161
   ....:     return sin(x*x*x)+(3*x*x)
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
In [4]: x = linspace(0,2*pi, 1000)
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   164
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   165
In [5]: plt.plot(x, f(x))
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   166
  \end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   167
  \inctime{10}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   168
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   169
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   170
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   171
% TIME: 10 m, running 
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   172
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   173
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   174
\section{Creating and running scripts}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   175
\begin{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   176
  {Creating python files}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   177
  \begin{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   178
    \item aka scripts
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   179
    \item use your editor
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   180
    \item extension \typ{.py}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   181
    \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
   182
    \item in IPython using \kwrd{\%run}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   183
  \end{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   184
\inctime{5}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   185
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   186
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   187
\section{Files Handling}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   188
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   189
  \frametitle{Basic File Operations}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   190
Opening and Reading files
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   191
\begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   192
In [6]: f = open('/path/to/file_name')
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   193
In [7]: data = f.read() # Read entire file.
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   194
In [8]: line = f.readline() # Read one line.
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   195
In [9]: f.close() # close the file.
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   196
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   197
Writing files
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   198
\begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   199
In [10]: f = open('/path/to/file_name', 'w')
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   200
In [11]: f.write('hello world\n')
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   201
In [12]: f.close()
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   202
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   203
\begin{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   204
    \item Everything read or written is a string
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   205
\end{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   206
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   207
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   208
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   209
    \frametitle{File and \kwrd{for}}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   210
\begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   211
In [13]: f = open('dummyfile')
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   212
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   213
In [14]: for line in f:
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   214
    ...:     print line
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   215
    ...:  
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   216
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   217
\inctime{10}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   218
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   219
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   220
\section{Strings}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   221
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   222
  \frametitle{Strings}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   223
  \begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   224
s = 'this is a string'
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   225
s = 'This one has "quotes" inside!'
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   226
s = "I have 'single-quotes' inside!"
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   227
l = "A string spanning many lines\
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   228
one more line\
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   229
yet another"
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   230
t = """A triple quoted string does
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   231
not need to be escaped at the end and 
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   232
"can have nested quotes" etc."""
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   233
  \end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   234
\end{frame}
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
\begin{frame}[fragile]\frametitle{Strings and \typ{split()}}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   237
  \begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   238
In [15]: a = 'hello world'
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   239
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   240
In [16]: a.split()
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   241
Out[17]: ['hello', 'world']
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   242
  \end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   243
Now try this:
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   244
  \begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   245
In [18]: b = 'KD, Madhu, Punchagan, Shantanu, Vattam'
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   246
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   247
In [19]: b.split(',')
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   248
Out[20]: ['KD', ' Madhu', ' Punchagan', ' Shantanu', ' Vattam']
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
\inctime{5}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   251
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   252
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   253
\section{Plotting points}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   254
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   255
\frametitle{How to plot points?}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   256
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
   257
\begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   258
In [21]: plt.plot(x, sin(x), 'ro')
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   259
Out[22]: [<matplotlib.lines.Line2D object at 0xac17e0c>]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   260
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   261
\begin{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   262
  \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
   263
  \item \kwrd{'o'} - Dots
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   264
  \item \kwrd{'-'} - Lines
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   265
  \item \kwrd{'- -'} - Dashed lines
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   266
\end{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   267
\inctime{5}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   268
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   269
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   270
\section{Lists}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   271
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   272
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   273
  \frametitle{List creation and indexing}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   274
\begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   275
In [23]: lst = [] #Empty list
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   276
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   277
In [24]: lst = [1,2,3,4] #More useful list
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   278
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   279
In [25]: len(lst)
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   280
Out[26]: 4
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   281
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   282
In [27]: lst[0]+lst[1]+lst[-1]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   283
Out[27]: 7
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   284
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   285
\begin{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   286
  \item Indices start with ?
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   287
  \item Negative indices indicate ?
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   288
  \end{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   289
\end{frame}
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
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   292
  \frametitle{List: slices}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   293
  \begin{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   294
  \item Slicing is a basic operation
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   295
  \item \typ{list[initial:final:step]}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   296
  \item  The step is optional
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   297
  \end{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   298
\begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   299
In [28]: lst[1:3]  # A slice.
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   300
Out[28]: [2, 3]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   301
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   302
In [29]: lst[1:-1]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   303
Out[29]: [2, 3]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   304
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   305
In [30]: lst[1:] == lst[1:-1]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   306
Out[30]: False
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   307
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   308
Explain last result
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   309
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   310
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   311
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   312
  \frametitle{List: more slices}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   313
\begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   314
In [31]: lst[0:-1:2] # Notice the step!
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   315
Out[31]: [1, 3]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   316
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   317
In [31]: lst[::2]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   318
Out[31]: [1, 3]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   319
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   320
In [32]: lst[-1::-1]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   321
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   322
What do you think the last one will do?
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   323
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   324
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   325
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   326
  \frametitle{List methods}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   327
\begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   328
In [33]: lst.append(5)
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   329
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   330
In [34]: lst
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   331
Out[34]: [1, 2, 3, 4, 5]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   332
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   333
In [35]: lst.append([6,7])
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   334
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   335
In [36]: lst
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   336
Out[36]: [1, 2, 3, 4, 5, [6, 7]]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   337
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   338
In [37]: lst.extend([8,9])
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   339
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   340
In [38]: lst
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   341
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
   342
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   343
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   344
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   345
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   346
  \frametitle{List containership}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   347
  \begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   348
In [39]: animals = ['cat', 'dog', 'rat', 'croc']
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   349
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   350
In [40]: 'dog' in animals
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   351
Out[40]: True
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   352
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   353
In [41]: 'snake' in animals
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   354
Out[41]: False
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   355
  \end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   356
  \inctime{10}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   357
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   358
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   359
\section{Modules and import}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   360
\begin{frame}{Modules and \typ{import}}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   361
  \begin{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   362
    \item \kwrd{import} x
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   363
    \item \kwrd{from} x \kwrd{import} y
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   364
  \end{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   365
Whats the difference??
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   366
\inctime{5}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   367
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   368
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   369
\end{document}