-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintro_python_trii_3.tex
254 lines (250 loc) · 7.99 KB
/
intro_python_trii_3.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
\documentclass[11pt]{beamer}
\usepackage[utf8]{inputenc}
%
\mode<presentation> {
\usetheme{CambridgeUS}
}
%
\setbeamercolor{frametitle}{fg=cyan!80!black}
\setbeamercolor{title}{fg=cyan!80!black}
\setbeamercolor{palette tertiary}{fg=black, bg=cyan}
\setbeamercolor{palette primary}{fg=black, bg=gray!30!white}
\setbeamercolor{palette secondary}{fg=black, bg=gray!20!white}
%
\setbeamertemplate{headline}
{
\leavevmode%
\hbox{%
% %\begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,right]{section in head/foot}%
% % \usebeamerfont{section in head/foot}\insertsectionhead\hspace*{2ex}
% %\end{beamercolorbox}%
% %\begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,left]{subsection in head/foot}%
% % \usebeamerfont{subsection in head/foot}\hspace*{2ex}\insertsubsectionhead
% %\end{beamercolorbox}
}%
\vskip0pt%
}
\setbeamertemplate{footline}{
\leavevmode%
\hbox{%
% %\begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
% % \usebeamerfont{author in head/foot}{Vipin @ R\"{a}tschLab}
% %\end{beamercolorbox}%
% %\begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
% % \usebeamerfont{title in head/foot}\insertshorttitle
% %\end{beamercolorbox}%
% %\begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,right]{date in head/foot}%
% %\usebeamerfont{date in head/foot}\insertshortdate{}\hspace*{2em}
% %\end{beamercolorbox}
}%
\vskip0pt%
}
%
\usepackage{graphicx}
\usepackage{booktabs}
\setbeamertemplate{navigation symbols}{}
\usepackage{listings}
\usepackage{color}
\definecolor{codecomment}{rgb}{152,0,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\definecolor{codekeys}{rgb}{30,0,100}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codecomment},
keywordstyle=\color{codekeys},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=4
}
\lstset{style=mystyle}
\newcommand{\thankyou}
{\begin{center} Would love to hear your experience! \\ [email protected] \\ [email protected] \end{center}}
%
\title[pyClass1]{Introduction to Programming with Python - Day 3}
\author{[email protected]}
%
\institute[cBio@MSKCC]
{
R{\"a}tsch Laboratory, Computational Biology Center\\
Memorial Sloan Kettering Cancer Center\\
}
\date{11 November 2014}
%
\begin{document}
\maketitle
%
%% Continue from Data structures
\begin{frame}[plain]
\frametitle{List Comprehensions}
\begin{itemize}
\item[] List comprehensions provide a concise way to create lists.
\pause
\lstinputlisting[language=Python]{scripts/list_comprehension_1.py}
\pause
\lstinputlisting[language=Python]{scripts/list_comprehension_2.py}
\pause
\lstinputlisting[language=Python]{scripts/list_comprehension_3.py}
\pause
\lstinputlisting[language=Python]{scripts/list_comprehension_4.py}
\end{itemize}
\end{frame}
%
\begin{frame}[plain]
\frametitle{del Statement}
\begin{itemize}
\item[] The \textbf{del} statement is to remove an item from a list given its index instead of its value.
\newline
\pause
\lstinputlisting[language=Python]{scripts/list_del.py}
\end{itemize}
\end{frame}
%%
\begin{frame}[plain]
\frametitle{Tuple - Another Data Type}
\begin{itemize}
\item[] Tuples are immutable, and usually contain an heterogeneous sequence of elements.
\newline
\pause
\lstinputlisting[language=Python]{scripts/tuple.py}
\end{itemize}
\end{frame}
%%
\begin{frame}[plain]
\frametitle{Defining Functions}
\begin{itemize}
\item[]Little self-contained programs that perform a specific task.
\newline
\pause
\item[] Which you can incorporate into your own, larger programs.
\newline
\pause
\item[] 'Calling' a function involves: \\
giving a function input, and it will return a value as output.
\newline
\pause
\item[] print 'Hello Python Class'
\newline
\pause
\item[] The keyword \textbf{def} introduces a function definition.
\end{itemize}
\end{frame}
%%
\begin{frame}[plain]
\frametitle{Defining Functions}
\begin{itemize}
\item[] function definition:
\lstinputlisting[language=Python]{scripts/factorial.py}
\pause
\item[] function call:
\lstinputlisting[language=Python]{scripts/call_factorial.py}
\end{itemize}
\end{frame}
%%
\begin{frame}[plain]
\frametitle{Modules}
\begin{itemize}
\item[] A module is a file containing Python definitions and statements.
\newline
\pause
\item[] factorial.py:
\lstinputlisting[language=Python]{scripts/factorial.py}
\pause
\item[] Import this module:
\lstinputlisting[language=Python]{scripts/import_module.py}
\end{itemize}
\end{frame}
%%
\begin{frame}[plain]
\frametitle{Regular Expression Operations}
\begin{itemize}
\item[] The module \textbf{\textit{re}} provides full support for regular expressions.
\pause
\item[] Meta characters:
\lstinputlisting[language=Python]{scripts/meta_char_1.py}
\pause
\item[] Predefined characters:
\lstinputlisting[language=Python]{scripts/meta_char_2.py}
\pause
\item[] For further references url: \url{https://docs.python.org/2/library/re.html}
\end{itemize}
\end{frame}
%%
\begin{frame}[plain]
\frametitle{Match Function}
\begin{itemize}
\item[] Syntax pattern for \textbf{match} function:
\newline
\lstinputlisting[language=Python]{scripts/re_match_1.py}
\pause
\lstinputlisting[language=Python]{scripts/re_match_2.py}
\end{itemize}
\end{frame}
%%
\begin{frame}[plain]
\frametitle{Matching vs Searching}
\begin{itemize}
\item[] \textbf{match} checks for a match only at the beginning of the string
\pause
\item[] \textbf{search} checks for a match anywhere in the string
\newline
\pause
\lstinputlisting[language=Python]{scripts/match_search.py}
\end{itemize}
\end{frame}
%%
\begin{frame}[plain]
\frametitle{Search and Replace}
\begin{itemize}
\item[] Some of the \textbf{re} methods that use regular expressions is \textbf{sub}.
\newline
\pause
\lstinputlisting[language=Python]{scripts/search_replace_1.py}
\pause
\lstinputlisting[language=Python]{scripts/search_replace_2.py}
\end{itemize}
\end{frame}
%%
\begin{frame}[plain]
\frametitle{Errors and Exceptions}
\begin{itemize}
\item[] \textbf{error} in syntax:
\lstinputlisting[language=Python]{scripts/syn_error.py}
\pause
\item[] \textbf{Exception} event, occurs during the execution of a program.
\lstinputlisting[language=Python]{scripts/excp_handle.py}
\pause
\item[] For further references: \url{https://docs.python.org/2/tutorial/errors.html}
\end{itemize}
\end{frame}
%%
\begin{frame}[plain]
\frametitle{The \textbf{assert} Statement}
\begin{itemize}
\item[] Python interpreter evaluates the expression,
\item[] If the expression is false, raises an \textbf{AssertionError} exception.
\newline
\pause
\lstinputlisting[language=Python]{scripts/assert_1.py}
\pause
\item[] Test case to check for valid user input phone numbers:
\newline
\lstinputlisting[language=Python]{scripts/assert_2.py}
\end{itemize}
\end{frame}
%
\begin{frame}[plain]
\thankyou
\end{frame}
\end{document}