summaryrefslogtreecommitdiff
path: root/day1/session2.tex
diff options
context:
space:
mode:
Diffstat (limited to 'day1/session2.tex')
-rw-r--r--day1/session2.tex95
1 files changed, 5 insertions, 90 deletions
diff --git a/day1/session2.tex b/day1/session2.tex
index bde3c98..965636e 100644
--- a/day1/session2.tex
+++ b/day1/session2.tex
@@ -164,10 +164,8 @@ In []: plt.plot(x, f(x))
\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 @@ In []: plt.plot(x, f(x))
\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 @@ In []: for line in f:
...: 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 @@ Out[]: ['KD', 'MCS', 'PC', 'SC', 'SV']
\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[]: [<matplotlib.lines.Line2D object at 0xac17e0c>]
@@ -263,13 +227,7 @@ Out[]: [<matplotlib.lines.Line2D object at 0xac17e0c>]
\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 @@ Out[]: 7
\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}