day1/session2.tex
author Puneeth Chaganti <punchagan@fossee.in>
Thu, 15 Oct 2009 22:43:51 +0530
changeset 130 8905a5badd7e
parent 118 c7f85ba59af3
child 132 c10d8cb8d690
permissions -rw-r--r--
Minor edits to day1 session2.
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
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
    54
\newcommand{\typ}[1]{\lstinline{#1}}
109
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
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
    76
\title[Basic 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}
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   136
In []: def plot_sinx():
109
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
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   142
In []: plot_sinx()
109
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}
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   149
In []: def f(x):
109
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
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   152
In []: x = linspace(0,2*pi, 1000)
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   153
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   154
In []: plt.plot(x, f(x))
109
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}
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   170
    \item run with \typ{python hello.py} at the command line
109
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
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   180
\begin{small}
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   181
\begin{lstlisting}
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   182
In []: f = open('hello.py')
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   183
In []: data = f.read() # Read entire file.
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   184
In []: line = f.readline() # Read 1 line.
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   185
In []: f.close() # close the file.
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   186
\end{lstlisting}
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   187
\end{small}
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   188
Writing files
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   189
\begin{lstlisting}
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   190
In []: f = open('hello.txt', 'w')
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   191
In []: f.write('hello world\n')
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   192
In []: f.close()
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   193
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   194
\begin{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   195
    \item Everything read or written is a string
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   196
\end{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   197
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   198
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   199
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   200
    \frametitle{File and \kwrd{for}}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   201
\begin{lstlisting}
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   202
In []: f = open('dummyfile')
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   203
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   204
In []: for line in f:
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   205
    ...:     print line
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   206
    ...:  
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   207
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   208
\inctime{10}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   209
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   210
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   211
\section{Strings}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   212
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   213
  \frametitle{Strings}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   214
  \begin{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   215
s = 'this is a string'
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   216
s = 'This one has "quotes" inside!'
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   217
s = "I have 'single-quotes' inside!"
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   218
l = "A string spanning many lines\
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   219
one more line\
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   220
yet another"
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   221
t = """A triple quoted string does
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   222
not need to be escaped at the end and 
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   223
"can have nested quotes" etc."""
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   224
  \end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   225
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   226
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   227
\begin{frame}[fragile]\frametitle{Strings and \typ{split()}}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   228
  \begin{lstlisting}
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   229
In []: a = 'hello world'
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   230
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   231
In []: a.split()
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   232
Out[]: ['hello', 'world']
109
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
Now try this:
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   235
  \begin{lstlisting}
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   236
In []: b = 'KD, MCS, PC, SC, SV'
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   237
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   238
In []: b.split(',')
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   239
Out[]: ['KD', 'MCS', 'PC', 'SC', 'SV']
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   240
  \end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   241
\inctime{5}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   242
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   243
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   244
\section{Plotting points}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   245
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   246
\frametitle{How to plot points?}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   247
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
   248
\begin{lstlisting}
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   249
In []: plt.plot(x, sin(x), 'ro')
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   250
Out[]: [<matplotlib.lines.Line2D object at 0xac17e0c>]
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   251
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   252
\begin{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   253
  \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
   254
  \item \kwrd{'o'} - Dots
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   255
  \item \kwrd{'-'} - Lines
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   256
  \item \kwrd{'- -'} - Dashed lines
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   257
\end{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   258
\inctime{5}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   259
\end{frame}
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
\section{Lists}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   262
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   263
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   264
  \frametitle{List creation and indexing}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   265
\begin{lstlisting}
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   266
In []: lst = [] #Empty list
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   267
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   268
In []: lst = [1,2,3,4] 
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   269
#More useful list
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   270
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   271
In []: len(lst)
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   272
Out[]: 4
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   273
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   274
In []: lst[0]+lst[1]+lst[-1]
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   275
Out[]: 7
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   276
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   277
\begin{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   278
  \item Indices start with ?
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   279
  \item Negative indices indicate ?
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   280
  \end{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   281
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   282
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   283
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   284
  \frametitle{List: slices}
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 Slicing is a basic operation
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   287
  \item \typ{list[initial:final:step]}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   288
  \item  The step is optional
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   289
  \end{itemize}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   290
\begin{lstlisting}
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   291
In []: lst[1:3]  # A slice.
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   292
Out[]: [2, 3]
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   293
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   294
In []: lst[1:-1]
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   295
Out[]: [2, 3]
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   296
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   297
In []: lst[1:] == lst[1:-1]
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   298
Out[]: False
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   299
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   300
Explain last result
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   301
\end{frame}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   302
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   303
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   304
  \frametitle{List: more slices}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   305
\begin{lstlisting}
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   306
In []: lst[0:-1:2] # Notice the step!
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   307
Out[]: [1, 3]
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   308
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   309
In []: lst[::2]
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   310
Out[]: [1, 3]
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   311
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   312
In []: lst[-1::-1]
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   313
\end{lstlisting}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   314
What do you think the last one will do?
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   315
\end{frame}
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
\begin{frame}[fragile]
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   318
  \frametitle{List methods}
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   319
\begin{lstlisting}
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   320
In []: lst.append(5)
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   321
In []: lst
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   322
Out[]: [1, 2, 3, 4, 5]
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   323
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   324
In []: lst.append([6,7])
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   325
In []: lst
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   326
Out[]: [1, 2, 3, 4, 5, [6, 7]]
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   327
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   328
In []: lst.extend([8,9])
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   329
In []: lst
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   330
Out[]: [1, 2, 3, 4, 5, [6, 7], 8, 9]
109
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}
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   337
In []: animals = ['cat', 'dog', 'rat', 'croc']
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   338
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   339
In []: 'dog' in animals
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   340
Out[]: True
109
16e04782baac Added session2.tex.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   341
130
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   342
In []: 'snake' in animals
8905a5badd7e Minor edits to day1 session2.
Puneeth Chaganti <punchagan@fossee.in>
parents: 118
diff changeset
   343
Out[]: False
109
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}