Added strings presentation.
authorShantanu <shantanu@fossee.in>
Wed, 21 Apr 2010 20:09:16 +0530
changeset 100 47a2ba7beaf8
parent 99 0bc1c9ec4fcf
child 101 3fe18d694d72
Added strings presentation.
presentations/strings.tex
strings.org
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/presentations/strings.tex	Wed Apr 21 20:09:16 2010 +0530
@@ -0,0 +1,112 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%Tutorial slides on Python.
+%
+% Author: FOSSEE 
+% Copyright (c) 2009, FOSSEE, IIT Bombay
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\documentclass[14pt,compress]{beamer}
+%\documentclass[draft]{beamer}
+%\documentclass[compress,handout]{beamer}
+%\usepackage{pgfpages} 
+%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm]
+
+% Modified from: generic-ornate-15min-45min.de.tex
+\mode<presentation>
+{
+  \usetheme{Warsaw}
+  \useoutertheme{infolines}
+  \setbeamercovered{transparent}
+}
+
+\usepackage[english]{babel}
+\usepackage[latin1]{inputenc}
+%\usepackage{times}
+\usepackage[T1]{fontenc}
+
+% Taken from Fernando's slides.
+\usepackage{ae,aecompl}
+\usepackage{mathpazo,courier,euler}
+\usepackage[scaled=.95]{helvet}
+
+\definecolor{darkgreen}{rgb}{0,0.5,0}
+
+\usepackage{listings}
+\lstset{language=Python,
+    basicstyle=\ttfamily\bfseries,
+    commentstyle=\color{red}\itshape,
+  stringstyle=\color{darkgreen},
+  showstringspaces=false,
+  keywordstyle=\color{blue}\bfseries}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Macros
+\setbeamercolor{emphbar}{bg=blue!20, fg=black}
+\newcommand{\emphbar}[1]
+{\begin{beamercolorbox}[rounded=true]{emphbar} 
+      {#1}
+ \end{beamercolorbox}
+}
+\newcounter{time}
+\setcounter{time}{0}
+\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
+
+\newcommand{\typ}[1]{\lstinline{#1}}
+
+\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }
+
+% Title page
+\title{Python for Scientific Computing : Strings and I/O operations}
+
+\author[FOSSEE] {FOSSEE}
+
+\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
+\date{}
+
+% DOCUMENT STARTS
+\begin{document}
+
+\begin{frame}
+  \maketitle
+\end{frame}
+
+\begin{frame}
+  \frametitle{About the Session}
+  \begin{block}{Goal}
+    \begin{itemize}
+    \item Strings and their manipulations
+    \item I/O operations
+    \end{itemize}  
+  \end{block}
+  \begin{block}{Prerequisites}
+    \begin{itemize}
+    \item Writing Python scripts
+    \item Basics of Lists
+    \end{itemize}    
+  \end{block}
+\end{frame}
+
+\begin{frame}[fragile]
+  \frametitle{Summary}
+  \begin{block}{}
+    \begin{itemize}
+    \item Creating string variables
+    \item Manipulating strings
+    \item I/O operations
+    \item Comments
+    \item Dynamically typed nature
+    \end{itemize}
+  \end{block}    
+\end{frame}
+
+\begin{frame}
+  \frametitle{Thank you!}  
+  \begin{block}{}
+  This session is part of \textcolor{blue}{FOSSEE} project funded by:
+  \begin{center}
+    \textcolor{blue}{NME through ICT from MHRD, Govt. of India}.
+  \end{center}  
+  \end{block}
+\end{frame}
+
+\end{document}
--- a/strings.org	Wed Apr 21 18:43:36 2010 +0530
+++ b/strings.org	Wed Apr 21 20:09:16 2010 +0530
@@ -24,11 +24,13 @@
     look at how to do elementary string manipulation, and simple input
     and output operations. 
     
-    As, we have seen in previous tutorials, anything enclosed within
-    quotes is a string. For example -
+    In Python anything enclosed within quotes is a string. Lets get 
+    started by starting ipython interpreter. We shall create some 
+    string variables by:
 
     a = 'This is a string'
     print a
+    type(a) shows it is 'str'
     b = "This too!"
     print b
 
@@ -44,11 +46,12 @@
     These are special type of strings, called docstrings, which shall
     be discussed along with functions. 
     
-    Like lists, which we already saw, string elements can be accessed
-    with their indexes. The indexing here, also, begins from 0. 
+    Like lists and arrays, which we have already seen, string elements 
+    can also be accessed with their indexes. The indexing here, also, 
+    begins from 0. 
 
-    print a[0]    
-    print a[5]
+    print a[0] gives us 'T'
+    print a[5] gives us 'i' which is 6th character.
 
     To access the last element, we can use -1 as the index!
     print a[-1]
@@ -60,7 +63,9 @@
     len(a)
 
     Python's strings support the operations + and *
+    + concatenates two strings.
     a + b
+    and * is used for replicating a string for given number of times.
     a * 4
     What do you think would happen when you do a * a?
     It's obviously an error since, it doesn't make any logical sense. 
@@ -93,20 +98,21 @@
     Python also has a 'join' function, which does the opposite of what
     split does. 
     ' '.join(alist) will return the original string a. 
+    This function takes list of elements(in our case alist) to be joined.
     '-'.join(alist) will return a string with the spaces in the string
     'a' replaced with hyphens. 
     
     At times we want our output or message in a particular
     format with variables embedded, something like printf in C. For 
     those situations python provides a provision. First lets create some 
-    variables
+    variables say
     * formatting - printf style *
       In []: x, y = 1, 1.234
       
       In []: print 'x is %s, y is %s' %(x, y)
       Out[]: 'x is 1, y is 1.234'
       Here %s means string, you can also try %d or %f for integer and 
-      float values.
+      float values respectively.
     * formatting - printf style *
 
 
@@ -151,11 +157,11 @@
     Before we wind up, a couple of miscellaneous things. 
     As you may have already noticed, Python is a dynamically typed
     language, that is you don't have to specify the type of a variable
-    when using a new one. You don't have to do anything special, to use
+    when using a new one. You don't have to do anything special, to 'reuse'
     a variable that was of int type as a float or string. 
     
-    a = 1
-    a = 1.1
+    a = 1 here a is integer
+    a = 1.1 now a float
     a = "Now I am a string!"
 
     Comments in Python start with a pound or hash sign. Anything after
@@ -166,7 +172,7 @@
     a = "# not a comment"
 
     we come to the end of this tutorial on strings introduction of Data types in
-    Python. In this tutorial we have learnt what are supported data types, 
-    supported operations and performing simple IO operations in Python.
+    Python. In this tutorial we have learnt what are supported operations and 
+    performing simple IO operations in Python.
 
 *** Notes