day2/session1.tex
author Shantanu <shantanu@fossee.in>
Wed, 28 Oct 2009 11:41:35 +0530
changeset 215 b69d0bdb136c
parent 204 87f914f38ba1
child 216 c6704d4a18bd
permissions -rw-r--r--
Session details,session 1 Day 1, 3Dploting->session3.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
135
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     2
%Tutorial slides on Python.
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     3
%
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     4
% Author: Prabhu Ramachandran <prabhu at aero.iitb.ac.in>
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     5
% Copyright (c) 2005-2009, Prabhu Ramachandran
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     6
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     7
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     8
\documentclass[14pt,compress]{beamer}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
     9
%\documentclass[draft]{beamer}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    10
%\documentclass[compress,handout]{beamer}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    11
%\usepackage{pgfpages} 
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    12
%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    13
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    14
% Modified from: generic-ornate-15min-45min.de.tex
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    15
\mode<presentation>
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    16
{
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    17
  \usetheme{Warsaw}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    18
  \useoutertheme{split}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    19
  \setbeamercovered{transparent}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    20
}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    21
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    22
\usepackage[english]{babel}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    23
\usepackage[latin1]{inputenc}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    24
%\usepackage{times}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    25
\usepackage[T1]{fontenc}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    26
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    27
% Taken from Fernando's slides.
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    28
\usepackage{ae,aecompl}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    29
\usepackage{mathpazo,courier,euler}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    30
\usepackage[scaled=.95]{helvet}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    31
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    32
\definecolor{darkgreen}{rgb}{0,0.5,0}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    33
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    34
\usepackage{listings}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    35
\lstset{language=Python,
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    36
    basicstyle=\ttfamily\bfseries,
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    37
    commentstyle=\color{red}\itshape,
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    38
  stringstyle=\color{darkgreen},
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    39
  showstringspaces=false,
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    40
  keywordstyle=\color{blue}\bfseries}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    41
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    42
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    43
% Macros
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    44
\setbeamercolor{emphbar}{bg=blue!20, fg=black}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    45
\newcommand{\emphbar}[1]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    46
{\begin{beamercolorbox}[rounded=true]{emphbar} 
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    47
      {#1}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    48
 \end{beamercolorbox}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    49
}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    50
\newcounter{time}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    51
\setcounter{time}{0}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    52
\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    53
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    54
\newcommand{\typ}[1]{\texttt{#1}}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    55
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    56
\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    57
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    58
%%% This is from Fernando's setup.
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    59
% \usepackage{color}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    60
% \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    61
% % Use and configure listings package for nicely formatted code
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    62
% \usepackage{listings}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    63
% \lstset{
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    64
%    language=Python,
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    65
%    basicstyle=\small\ttfamily,
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    66
%    commentstyle=\ttfamily\color{blue},
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    67
%    stringstyle=\ttfamily\color{orange},
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    68
%    showstringspaces=false,
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    69
%    breaklines=true,
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    70
%    postbreak = \space\dots
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    71
% }
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    72
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    73
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    74
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    75
% Title page
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    76
\title[Basic Python]{Python:\\A formal approach}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    77
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    78
\author[FOSSEE Team] {The FOSSEE Group}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    79
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    80
\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    81
\date[] {1, November 2009\\Day 2, Session 1}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    82
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    83
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    84
%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    85
%\logo{\pgfuseimage{iitmlogo}}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    86
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    87
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
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
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    89
%% the beginning of each subsection:
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    90
\AtBeginSubsection[]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    91
{
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    92
  \begin{frame}<beamer>
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    93
    \frametitle{Outline}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    94
    \tableofcontents[currentsection,currentsubsection]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    95
  \end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    96
}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    97
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    98
\AtBeginSection[]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
    99
{
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   100
  \begin{frame}<beamer>
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   101
    \frametitle{Outline}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   102
    \tableofcontents[currentsection,currentsubsection]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   103
  \end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   104
}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   105
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   106
% If you wish to uncover everything in a step-wise fashion, uncomment
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   107
% the following command: 
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   108
%\beamerdefaultoverlayspecification{<+->}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   109
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   110
%\includeonlyframes{current,current1,current2,current3,current4,current5,current6}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   111
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   112
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   113
% DOCUMENT STARTS
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   114
\begin{document}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   115
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   116
\begin{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   117
  \titlepage
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   118
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   119
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   120
\begin{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   121
  \frametitle{Outline}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   122
  \tableofcontents
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   123
  % You might wish to add the option [pausesections]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   124
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   125
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   126
\section{Data types}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   127
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   128
\begin{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   129
  \frametitle{Primitive Data types}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   130
  \begin{itemize}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   131
    \item Numbers: float, int, complex
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   132
    \item Strings
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   133
    \item Boolean
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   134
  \end{itemize}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   135
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   136
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   137
\subsection{Numbers}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   138
\begin{frame}[fragile]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   139
  \frametitle{Numbers}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   140
  \begin{itemize}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   141
    \item \kwrd{int}\\ Any whole number is an \kwrd{int}, no matter what the size!
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   142
  \begin{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   143
In []: a = 13
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   144
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   145
In []: a = 99999999999999999999
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   146
  \end{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   147
    \item \kwrd{float}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   148
  \begin{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   149
In []: fl = 3.141592
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   150
  \end{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   151
  \end{itemize}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   152
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   153
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   154
\begin{frame}[fragile]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   155
\frametitle{Complex numbers}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   156
  \begin{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   157
In []: cplx = 3+4j
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   158
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   159
In []: abs(cplx)
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   160
Out[]: 5.0
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   161
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   162
In []: cplx.imag
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   163
Out[]: 4.0
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   164
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   165
In []: cplx.real
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   166
Out[]: 3.0
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   167
  \end{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   168
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   169
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   170
\subsection{Boolean}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   171
\begin{frame}{Boolean}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   172
  \begin{itemize}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   173
    \item \kwrd{True}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   174
    \item \kwrd{False}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   175
    \item \kwrd{not}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   176
    \item \kwrd{and}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   177
    \item \kwrd{or}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   178
  \end{itemize}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   179
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   180
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   181
\subsection{Strings}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   182
\begin{frame}[fragile]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   183
  \frametitle{String methods}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   184
Strings were introduced previously, let us now look at them in a little more detail.
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   185
  \begin{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   186
In []: a = 'hello world'
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   187
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   188
In []: a.startswith('hell')
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   189
Out[]: True
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   190
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   191
In []: a.endswith('ld')
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   192
Out[]: True
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   193
  \end{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   194
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   195
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   196
\begin{frame}[fragile]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   197
\frametitle{Still with strings}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   198
We saw split() previously. join() is the opposite of split()
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   199
  \begin{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   200
In []: ''.join(['a', 'b', 'c'])
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   201
Out[]: 'abc'
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   202
  \end{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   203
  \begin{block}{Note:}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   204
Strings are immutable.\\ That is string variables cannot be changed.
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   205
  \end{block}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   206
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   207
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   208
\begin{frame}[fragile]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   209
\frametitle{String formatting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   210
  \begin{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   211
In []: x, y = 1, 1.234
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   212
In []: 'x is %s, y is %s' %(x, y)
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   213
Out[]: 'x is 1, y is 1.234'
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   214
  \end{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   215
  \small
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   216
\url{docs.python.org/lib/typesseq-strings.html}\\
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   217
\inctime{10}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   218
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   219
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   220
\section{Relational and logical operators}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   221
\begin{frame}[fragile]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   222
  \frametitle{Relational and logical operators}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   223
  \begin{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   224
In []: pos, zer, neg = 1, 0, -1
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   225
In []: pos == neg
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   226
Out[]: False
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   227
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   228
In []: pos >= neg
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   229
Out[]: True
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   230
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   231
In []: neg < zer < pos
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   232
Out[]: True
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   233
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   234
In []: pos + neg != zer
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   235
Out[]: False
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   236
  \end{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   237
\inctime{5}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   238
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   239
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   240
\begin{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   241
  {A classic problem}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   242
  \begin{block}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   243
    {Interchange values}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   244
    How to interchange values of two variables? 
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   245
  \end{block}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   246
  \pause
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   247
  \begin{block}{Note:}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   248
    This Python idiom works for all types of variables.\\
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   249
They need not be of the same type!
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   250
  \end{block}
204
87f914f38ba1 Session 3 day 1, Statistical operations finalized.
Madhusudan.C.S <madhusudancs@gmail.com>
parents: 140
diff changeset
   251
  \inctime{10}
135
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   252
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   253
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   254
\section{Control flow}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   255
\begin{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   256
  \frametitle{Control flow constructs}  
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   257
  \begin{itemize}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   258
  \item \kwrd{if/elif/else}: branching
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   259
  \item \kwrd{while}: looping
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   260
  \item \kwrd{for}: iterating 
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   261
  \item \kwrd{break, continue}: modify loop 
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   262
  \item \kwrd{pass}: syntactic filler
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   263
  \end{itemize}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   264
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   265
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   266
\subsection{Basic Conditional flow}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   267
\begin{frame}[fragile]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   268
  \frametitle{\typ{If...elif...else} example}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   269
\begin{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   270
x = int(raw_input("Enter an integer:"))
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   271
if x < 0:
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   272
     print 'Be positive!'
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   273
elif x == 0:
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   274
     print 'Zero'
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   275
elif x == 1:
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   276
     print 'Single'
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   277
else:
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   278
     print 'More'
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   279
\end{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   280
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   281
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   282
\begin{frame}{Simple IO}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   283
  \begin{block}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   284
    {Console Input}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   285
    \texttt{raw\_input()} waits for user input.\\Prompt string is optional.\\
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   286
    All keystrokes are Strings!\\\texttt{int()} converts string to int.
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   287
  \end{block}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   288
  \begin{block}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   289
    {Console output}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   290
    \texttt{print} is straight forward. Note the distinction between \texttt{print x} and \texttt{print x,}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   291
  \end{block}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   292
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   293
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   294
\subsection{Basic Looping}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   295
\begin{frame}[fragile]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   296
  \frametitle{\kwrd{while}}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   297
Example: Fibonacci series
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   298
  \begin{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   299
# the sum of two elements
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   300
# defines the next
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   301
a, b = 0, 1
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   302
while b < 10:
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   303
    print b,
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   304
    a, b = b, a + b 
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   305
\end{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   306
\typ{1 1 2 3 5 8}\\  
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   307
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   308
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   309
\begin{frame}[fragile]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   310
\frametitle{\kwrd{range()}}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   311
\kwrd{range([start,] stop[, step])}\\
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   312
\begin{itemize}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   313
  \item \alert {range() returns a list of integers}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   314
  \item \alert {The start and the step arguments are optional}  
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   315
\end{itemize}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   316
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   317
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   318
\begin{frame}[fragile]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   319
  \frametitle{\kwrd{for}}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   320
Example: print squares of first \typ{n} numbers
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   321
  \begin{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   322
In []: for i in range(5):
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   323
 ....:     print i, i * i
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   324
 ....:     
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   325
 ....:     
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   326
0 0
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   327
1 1
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   328
2 4
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   329
3 9
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   330
4 16
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   331
\end{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   332
\inctime{15}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   333
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   334
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   335
\section{Lists}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   336
\begin{frame}[fragile]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   337
\frametitle{More List methods}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   338
\begin{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   339
In []: lst = [1,2,3,4,5,6,7,8]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   340
In []: lst.reverse()
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   341
In []: lst
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   342
Out[]: [8, 7, 6, 5, 4, 3, 2, 1]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   343
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   344
In []: lst.extend([0, -1, -2])
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   345
In []: lst
140
fe6a38572a65 Added changes suggested by PR for session 1 day 1.
Shantanu <shantanu@fossee.in>
parents: 135
diff changeset
   346
Out[]: [8, 7, 6, 5, 4, 3, 2, 1, 0, -1]
135
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   347
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   348
In []: lst.remove(0)
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   349
In []: lst
140
fe6a38572a65 Added changes suggested by PR for session 1 day 1.
Shantanu <shantanu@fossee.in>
parents: 135
diff changeset
   350
Out[]: [8, 7, 6, 5, 4, 3, 2, 1, -1]
135
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   351
\end{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   352
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   353
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   354
\begin{frame}[fragile]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   355
\frametitle{List containership}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   356
\begin{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   357
In []: a = 8
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   358
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   359
In []: a in lst
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   360
Out[]: True
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   361
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   362
In []: b = 10
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   363
In []: b in lst
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   364
Out[]: False
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   365
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   366
In []: b not in lst
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   367
Out[]: True
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   368
\end{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   369
\inctime{10}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   370
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   371
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   372
\section{Tuples}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   373
\begin{frame}[fragile]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   374
\frametitle{Tuples: Immutable lists}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   375
\begin{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   376
In []: tup = (1,2,3,4,5,6,7,8)
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   377
In []: tup[0]+tup[3]+tup[-1]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   378
Out[]: 13
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   379
\end{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   380
\begin{block}{Note:}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   381
\begin{itemize}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   382
\item Tuples are immutable - cannot be changed
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   383
\item Multiple return values in a function are actually tuples
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   384
\item Tuples are working behind the scenes in exchanging values - Tuple Unpacking
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   385
\end{itemize}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   386
\end{block}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   387
\inctime{5}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   388
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   389
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   390
\section{Dictionaries}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   391
\begin{frame}[fragile]
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   392
\frametitle{Dictionaries}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   393
  \alert {lists and tuples: integer indexes :: dictionaries: string indexes}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   394
\begin{lstlisting}
140
fe6a38572a65 Added changes suggested by PR for session 1 day 1.
Shantanu <shantanu@fossee.in>
parents: 135
diff changeset
   395
In []: player = {'Mat': 134,'Inn': 233, 
fe6a38572a65 Added changes suggested by PR for session 1 day 1.
Shantanu <shantanu@fossee.in>
parents: 135
diff changeset
   396
           'Runs': 10823, 'Avg': 52.53}
135
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   397
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   398
In []: player['Avg']
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   399
Out[]: 52.530000000000001
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   400
In []: player.keys()
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   401
Out[]: ['Runs', 'Inn', 'Avg', 'Mat']
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   402
In []: player.values()
140
fe6a38572a65 Added changes suggested by PR for session 1 day 1.
Shantanu <shantanu@fossee.in>
parents: 135
diff changeset
   403
Out[]: [10823, 233, 
fe6a38572a65 Added changes suggested by PR for session 1 day 1.
Shantanu <shantanu@fossee.in>
parents: 135
diff changeset
   404
       52.530000000000001, 134]
135
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   405
\end{lstlisting}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   406
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   407
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   408
\begin{frame}{Dictionaries}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   409
\begin{itemize}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   410
\item Duplicate keys are not allowed!
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   411
\item Dictionaries are iterable through keys.
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   412
\end{itemize}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   413
\inctime{5}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   414
\end{frame}
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   415
a5da7607ab14 Added Session 1, Day 2 - "Formal approach to Python" slides.
Santosh G. Vattam <vattam.santosh@gmail.com>
parents:
diff changeset
   416
\end{document}