# HG changeset patch # User Santosh G. Vattam # Date 1256029875 -19800 # Node ID c10d8cb8d6904a76b588bc0c9a68e868cdfe874d # Parent b3a78754c4a990491e81750d68fcd68afa206f41 Updated session 2 slides. diff -r b3a78754c4a9 -r c10d8cb8d690 day1/session2.tex --- a/day1/session2.tex Thu Oct 15 23:10:03 2009 +0530 +++ b/day1/session2.tex Tue Oct 20 14:41:15 2009 +0530 @@ -164,10 +164,8 @@ \begin{frame} {Creating python files} \begin{itemize} - \item aka scripts \item use your editor \item extension \typ{.py} - \item run with \typ{python hello.py} at the command line \item in IPython using \kwrd{\%run} \end{itemize} \inctime{5} @@ -175,28 +173,6 @@ \section{Files Handling} \begin{frame}[fragile] - \frametitle{Basic File Operations} -Opening and Reading files -\begin{small} -\begin{lstlisting} -In []: f = open('hello.py') -In []: data = f.read() # Read entire file. -In []: line = f.readline() # Read 1 line. -In []: f.close() # close the file. -\end{lstlisting} -\end{small} -Writing files -\begin{lstlisting} -In []: f = open('hello.txt', 'w') -In []: f.write('hello world\n') -In []: f.close() -\end{lstlisting} -\begin{itemize} - \item Everything read or written is a string -\end{itemize} -\end{frame} - -\begin{frame}[fragile] \frametitle{File and \kwrd{for}} \begin{lstlisting} In []: f = open('dummyfile') @@ -205,23 +181,12 @@ ...: print line ...: \end{lstlisting} -\inctime{10} +\inctime{5} \end{frame} \section{Strings} -\begin{frame}[fragile] - \frametitle{Strings} - \begin{lstlisting} -s = 'this is a string' -s = 'This one has "quotes" inside!' -s = "I have 'single-quotes' inside!" -l = "A string spanning many lines\ -one more line\ -yet another" -t = """A triple quoted string does -not need to be escaped at the end and -"can have nested quotes" etc.""" - \end{lstlisting} +\begin{frame}{Strings} +Anything within ``quotes'' is a string! \end{frame} \begin{frame}[fragile]\frametitle{Strings and \typ{split()}} @@ -244,7 +209,6 @@ \section{Plotting points} \begin{frame}[fragile] \frametitle{How to plot points?} -We saw how to plot graphs, lets now look at how to plot points.\\ \begin{lstlisting} In []: plt.plot(x, sin(x), 'ro') Out[]: [] @@ -263,13 +227,7 @@ \begin{frame}[fragile] \frametitle{List creation and indexing} \begin{lstlisting} -In []: lst = [] #Empty list - In []: lst = [1,2,3,4] -#More useful list - -In []: len(lst) -Out[]: 4 In []: lst[0]+lst[1]+lst[-1] Out[]: 7 @@ -282,67 +240,24 @@ \begin{frame}[fragile] \frametitle{List: slices} - \begin{itemize} - \item Slicing is a basic operation - \item \typ{list[initial:final:step]} - \item The step is optional - \end{itemize} + \typ{list[initial:final:step]} \begin{lstlisting} In []: lst[1:3] # A slice. Out[]: [2, 3] In []: lst[1:-1] Out[]: [2, 3] - -In []: lst[1:] == lst[1:-1] -Out[]: False \end{lstlisting} -Explain last result -\end{frame} - -\begin{frame}[fragile] - \frametitle{List: more slices} -\begin{lstlisting} -In []: lst[0:-1:2] # Notice the step! -Out[]: [1, 3] - -In []: lst[::2] -Out[]: [1, 3] - -In []: lst[-1::-1] -\end{lstlisting} -What do you think the last one will do? \end{frame} \begin{frame}[fragile] \frametitle{List methods} \begin{lstlisting} -In []: lst.append(5) -In []: lst -Out[]: [1, 2, 3, 4, 5] - In []: lst.append([6,7]) In []: lst Out[]: [1, 2, 3, 4, 5, [6, 7]] - -In []: lst.extend([8,9]) -In []: lst -Out[]: [1, 2, 3, 4, 5, [6, 7], 8, 9] \end{lstlisting} -\end{frame} - -\begin{frame}[fragile] - \frametitle{List containership} - \begin{lstlisting} -In []: animals = ['cat', 'dog', 'rat', 'croc'] - -In []: 'dog' in animals -Out[]: True - -In []: 'snake' in animals -Out[]: False - \end{lstlisting} - \inctime{10} +\inctime{10} \end{frame} \section{Modules and import}