summaryrefslogtreecommitdiff
path: root/advanced_python
diff options
context:
space:
mode:
authorPrabhu Ramachandran2017-11-11 23:56:07 +0530
committerPrabhu Ramachandran2017-11-11 23:56:07 +0530
commita754b05d4a4c9686f9efe355408aaaec02a7e211 (patch)
tree236683821ec5004418f4bbc1787ca712562ac343 /advanced_python
parent69728d2fefda84c104a06c3282082421accd7775 (diff)
downloadpython-workshops-a754b05d4a4c9686f9efe355408aaaec02a7e211.tar.gz
python-workshops-a754b05d4a4c9686f9efe355408aaaec02a7e211.tar.bz2
python-workshops-a754b05d4a4c9686f9efe355408aaaec02a7e211.zip
Getting started on advanced Python slides.
Diffstat (limited to 'advanced_python')
-rw-r--r--advanced_python/Makefile15
-rw-r--r--advanced_python/README.md18
-rw-r--r--advanced_python/data/a_1_b_2.pngbin0 -> 27249 bytes
-rw-r--r--advanced_python/data/a_b_eq_1.pngbin0 -> 26470 bytes
-rw-r--r--advanced_python/data/a_b_list.pngbin0 -> 49387 bytes
-rw-r--r--advanced_python/data/a_b_list1.pngbin0 -> 58076 bytes
-rw-r--r--advanced_python/data/a_eq_1.pngbin0 -> 22073 bytes
-rw-r--r--advanced_python/data/a_list_b_2.pngbin0 -> 48176 bytes
-rw-r--r--advanced_python/data/a_str_b_list.pngbin0 -> 69306 bytes
-rw-r--r--advanced_python/data/a_str_b_list_compact.pngbin0 -> 30791 bytes
-rw-r--r--advanced_python/macros.tex88
-rw-r--r--advanced_python/names_objects.tex337
12 files changed, 458 insertions, 0 deletions
diff --git a/advanced_python/Makefile b/advanced_python/Makefile
new file mode 100644
index 0000000..12f21fd
--- /dev/null
+++ b/advanced_python/Makefile
@@ -0,0 +1,15 @@
+.SUFFIXES: .tex .pdf
+
+.tex.pdf:
+ pdflatex $*.tex
+ pdflatex $*.tex
+
+SLIDES= names_objects.pdf
+
+all: $(SLIDES)
+
+cleanall:
+ rm -f *.dvi *.log *.bak *.aux *.bbl *.blg *.idx *.ps *.eps *.pdf *.toc *.out *~ *.vrb *.nav *.snm
+
+clean:
+ rm -f *.log *.bak *.aux *.bbl *.blg *.idx *.toc *.out *~ *.vrb *.nav *.snm *.synctex.gz
diff --git a/advanced_python/README.md b/advanced_python/README.md
new file mode 100644
index 0000000..8237ac3
--- /dev/null
+++ b/advanced_python/README.md
@@ -0,0 +1,18 @@
+# Advanced Python Programming
+
+This material covers some advanced Python programming concepts.
+
+The student is supposed to have completed the "Basic Python Programming"
+course first before starting on this material.
+
+As done for the basic Python course, the material here is completely hands-on
+and requires the use of yaksh for practice, self-assessment, and assessment.
+
+## Pre-requisites
+
+- Students should have completed the basic Python programming material.
+- One should have a Python 3.x installation.
+- Use a reasonable editor, Canopy will work.
+- If one desires a more advanced editor, I suggest VS Code
+ (https://code.visualstudio.com/) which is free, open source, and very
+ powerful.
diff --git a/advanced_python/data/a_1_b_2.png b/advanced_python/data/a_1_b_2.png
new file mode 100644
index 0000000..a86be2c
--- /dev/null
+++ b/advanced_python/data/a_1_b_2.png
Binary files differ
diff --git a/advanced_python/data/a_b_eq_1.png b/advanced_python/data/a_b_eq_1.png
new file mode 100644
index 0000000..d79931a
--- /dev/null
+++ b/advanced_python/data/a_b_eq_1.png
Binary files differ
diff --git a/advanced_python/data/a_b_list.png b/advanced_python/data/a_b_list.png
new file mode 100644
index 0000000..d16fe8a
--- /dev/null
+++ b/advanced_python/data/a_b_list.png
Binary files differ
diff --git a/advanced_python/data/a_b_list1.png b/advanced_python/data/a_b_list1.png
new file mode 100644
index 0000000..ae0b5a0
--- /dev/null
+++ b/advanced_python/data/a_b_list1.png
Binary files differ
diff --git a/advanced_python/data/a_eq_1.png b/advanced_python/data/a_eq_1.png
new file mode 100644
index 0000000..629f9fe
--- /dev/null
+++ b/advanced_python/data/a_eq_1.png
Binary files differ
diff --git a/advanced_python/data/a_list_b_2.png b/advanced_python/data/a_list_b_2.png
new file mode 100644
index 0000000..5ccaae2
--- /dev/null
+++ b/advanced_python/data/a_list_b_2.png
Binary files differ
diff --git a/advanced_python/data/a_str_b_list.png b/advanced_python/data/a_str_b_list.png
new file mode 100644
index 0000000..4994bc1
--- /dev/null
+++ b/advanced_python/data/a_str_b_list.png
Binary files differ
diff --git a/advanced_python/data/a_str_b_list_compact.png b/advanced_python/data/a_str_b_list_compact.png
new file mode 100644
index 0000000..be5310b
--- /dev/null
+++ b/advanced_python/data/a_str_b_list_compact.png
Binary files differ
diff --git a/advanced_python/macros.tex b/advanced_python/macros.tex
new file mode 100644
index 0000000..37a70ba
--- /dev/null
+++ b/advanced_python/macros.tex
@@ -0,0 +1,88 @@
+
+% Modified from: generic-ornate-15min-45min.de.tex
+\mode<presentation>
+{
+ \usetheme{Warsaw}
+ \useoutertheme{infolines}
+ \setbeamercovered{invisible}
+}
+
+\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]{\textbf{\texttt{{#1}}}}
+
+
+\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} }
+
+%%% This is from Fernando's setup.
+% \usepackage{color}
+% \definecolor{orange}{cmyk}{0,0.4,0.8,0.2}
+% % Use and configure listings package for nicely formatted code
+% \usepackage{listings}
+% \lstset{
+% language=Python,
+% basicstyle=\small\ttfamily,
+% commentstyle=\ttfamily\color{blue},
+% stringstyle=\ttfamily\color{orange},
+% showstringspaces=false,
+% breaklines=true,
+% postbreak = \space\dots
+% }
+
+%\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo}
+%\logo{\pgfuseimage{iitmlogo}}
+
+
+%% Delete this, if you do not want the table of contents to pop up at
+%% the beginning of each subsection:
+\AtBeginSubsection[]
+{
+ \begin{frame}<beamer>
+ \frametitle{Outline}
+ \tableofcontents[currentsection,currentsubsection]
+ \end{frame}
+}
+
+\AtBeginSection[]
+{
+ \begin{frame}<beamer>
+ \frametitle{Outline}
+ \tableofcontents[currentsection,currentsubsection]
+ \end{frame}
+}
+
+% If you wish to uncover everything in a step-wise fashion, uncomment
+% the following command:
+%\beamerdefaultoverlayspecification{<+->}
+
+%\includeonlyframes{current,current1,current2,current3,current4,current5,current6}
diff --git a/advanced_python/names_objects.tex b/advanced_python/names_objects.tex
new file mode 100644
index 0000000..f7ef9a6
--- /dev/null
+++ b/advanced_python/names_objects.tex
@@ -0,0 +1,337 @@
+\documentclass[14pt,compress]{beamer}
+
+\input{macros.tex}
+
+\title[Names and Objects]{Advanced Python}
+\subtitle{Statements, Expressions, Names, and Objects}
+
+\author[FOSSEE] {The FOSSEE Group}
+
+\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
+\date[] {Mumbai, India}
+
+\begin{document}
+
+\begin{frame}
+ \titlepage
+\end{frame}
+
+\begin{frame}
+ \frametitle{Overview}
+ \begin{itemize}
+ \item Statements
+ \item Expressions
+ \item Variables
+ \item Objects
+ \item Names
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Recap of essential concepts}
+ \begin{itemize}
+ \item Mutable data types
+ \item Immutable data types
+ \end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Expressions}
+ \begin{itemize}
+ \item Evaluate to something
+ \item Describe some computation
+ \item Python evaluates expressions
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Examples of Expressions}
+ \small
+ \begin{lstlisting}
+In []: 1
+Out[]: 1
+
+In []: (1 + 1.2) * 2.0
+Out[]: 4.4
+
+In []: sin(0.1)
+Out[]: 0.09983341664682815
+
+In []: (2 > 1) and (3 > 2)
+Out[]: True
+
+In []: [1, 2, 3, 4][::2]
+Out[]: [1, 3]
+# Note that each has an output
+ \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Statements}
+ \begin{itemize}
+ \item Instruct Python to perform some action
+ \item A program is a series of statements
+ \item A statement can have expressions
+ \item Assignments are statements
+ \end{itemize}
+\begin{lstlisting}
+In []: a = 1
+
+In []: a += 1
+\end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Assignment statements}
+ \begin{lstlisting}
+In []: a = 1
+
+In []: a = 'hello'
+\end{lstlisting}
+\begin{itemize}
+\item These are assignment statements
+\item Values are \emph{Objects}
+\end{itemize}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Objects}
+ \begin{itemize}
+ \item Objects: all data in Python
+ \item Have an identity, type, and value
+ \item Identity is checked using \typ{is}
+ \item Identity and type cannot change
+ \item Value of mutables change
+ \item Immutable object value cannot change
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Names and objects}
+ \begin{itemize}
+ \item Assignment binds a name to an object
+ \end{itemize}
+ \begin{lstlisting}
+In []: a = 1
+
+In []: b = 1
+ \end{lstlisting}
+ \begin{itemize}
+ \item \typ{a} is a name for the object \typ{1}
+ \item \typ{b} is also a name for the same object \typ{1}
+ \end{itemize}
+ \begin{lstlisting}
+In []: b = a # The same as above
+\end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Visualizing this}
+ \begin{minipage}{0.4\textwidth}
+ \begin{lstlisting}
+In []: a = 1
+ \end{lstlisting}
+ \end{minipage}
+ \begin{minipage}{0.4\textwidth}
+ \includegraphics[width=2.5in]{data/a_eq_1.png}
+ \end{minipage}
+\pause
+ \begin{minipage}{0.4\textwidth}
+ \begin{lstlisting}
+In []: b = a
+ \end{lstlisting}
+ \end{minipage}
+ \begin{minipage}{0.4\textwidth}
+ \includegraphics[width=2.5in]{data/a_b_eq_1.png}
+ \end{minipage}
+
+ {\small Made with: \url{pythontutor.com}}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Visualizing this ...}
+ Set \typ{b} to something else:
+
+ \begin{minipage}{0.4\textwidth}
+ \begin{lstlisting}
+In []: a = 1
+
+In []: b = 2
+ \end{lstlisting}
+ \end{minipage}
+ \begin{minipage}{0.4\textwidth}
+ \includegraphics[width=2.5in]{data/a_1_b_2.png}
+ \end{minipage}
+
+ \vspace*{1in}
+ {\small Made with: \url{pythontutor.com}}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Names and objects ...}
+ \begin{itemize}
+ \item More interesting when \typ{a} is a list
+ \end{itemize}
+ \begin{minipage}{0.4\textwidth}
+ \begin{lstlisting}
+In []: a = [1, 2]
+\end{lstlisting}
+\end{minipage}
+ \begin{minipage}{0.4\textwidth}
+ \hspace*{0.2in}\includegraphics[width=2.25in]{data/a_list_b_2.png}
+ \end{minipage}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Names and objects ...}
+ \begin{minipage}{0.4\textwidth}
+ \begin{lstlisting}
+In []: b = a
+\end{lstlisting}
+\end{minipage}
+ \begin{minipage}{0.4\textwidth}
+ \hspace*{0.2in}\includegraphics[width=2.25in]{data/a_b_list.png}
+ \end{minipage}
+ \pause
+ \begin{itemize}
+ \item \typ{a} is a name for the object \typ{[1, 2]}
+ \item \typ{b} is also a name for the \alert{same object}
+ \item Changing the contents of \typ{a} reflect in \typ{b}
+ \end{itemize}
+\end{frame}
+
+
+\begin{frame}[fragile]
+ \frametitle{Names and objects ...}
+ \begin{minipage}{0.4\textwidth}
+ \begin{lstlisting}
+In []: a.append(3)
+
+In []: b
+Out[]: [1, 2, 3]
+ \end{lstlisting}
+\end{minipage}
+ \begin{minipage}{0.4\textwidth}
+ \hspace*{0.4in}\includegraphics[width=2.25in]{data/a_b_list1.png}
+ \end{minipage}
+
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Names and objects ...}
+ \begin{minipage}{0.4\textwidth}
+ \begin{itemize}
+ \item Re-assign \typ{a}
+ \end{itemize}
+ \begin{lstlisting}
+In []: a = 'hello'
+\end{lstlisting}
+\pause
+\end{minipage}
+ \begin{minipage}{0.4\textwidth}
+ \hspace*{0.4in}\includegraphics[width=2.25in]{data/a_str_b_list.png}
+ \end{minipage}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Names and objects ...}
+ Rendered more compactly:
+ \vspace*{0.25in}
+ \begin{center}
+ \includegraphics[width=3in]{data/a_str_b_list_compact.png}
+ \end{center}
+ \vspace*{0.5in}
+ {\small Made with: \url{pythontutor.com}}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Summary}
+ \begin{itemize}
+ \item Expressions: evaluate to something
+ \item Statements: instruct Python to do something
+ \item Objects: identity, type, value
+ \item Assignments bind names to objects
+ \item Frame: an environment for bindings
+ \item Explore \url{pythontutor.com}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Exercise 1}
+\begin{lstlisting}
+a = [1, 2]
+b = a
+c = [10, 20]
+a.append(c)
+del b
+c.append(30)
+del c
+a[-1].append(40)
+a = 1
+\end{lstlisting}
+\vspace*{0.1in}
+ \begin{itemize}
+ \item Run step-by-step on \url{pythontutor.com}
+ \item Predict the output before you see the answer
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Exercise 2}
+\begin{lstlisting}
+a = [1, 2]
+c = [10, 20]
+a.append(c)
+
+c.append(a)
+a.append(a)
+\end{lstlisting}
+\vspace*{0.1in}
+
+ \begin{itemize}
+ \item Run step-by-step on \url{pythontutor.com}
+ \item Predict the output before you see the answer
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Exercise 3}
+\begin{lstlisting}
+x = [1, 2]
+y = 'hello'
+
+def f(x):
+ y = x + 1
+ return x*y
+
+f(2)
+\end{lstlisting}
+\vspace*{0.1in}
+ \begin{itemize}
+ \item Run step-by-step on \url{pythontutor.com}
+ \item Predict the output before you see the answer
+ \end{itemize}
+
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Exercise 4}
+\begin{lstlisting}
+def f(x):
+ def g(x):
+ return x + 1
+ return g(x)
+
+f(1)
+f(2)
+\end{lstlisting}
+\vspace*{0.1in}
+ \begin{itemize}
+ \item Run step-by-step on \url{pythontutor.com}
+ \item Predict the output before you see the answer
+ \end{itemize}
+
+\end{frame}
+
+
+\end{document}