extended types
[linuxnijmegen-python.git] / p.tex
1 %&p
2 \begin{document}
3 \frame{\titlepage}
4
5 \section{Introduction}
6 \begin{frame}
7 \frametitle{What is Python}
8 \includegraphics[width=\linewidth]{2.png}
9 \end{frame}
10
11 \begin{frame}
12 \frametitle{What is Python}
13 \begin{itemize}
14 \item Interpreted
15 \item Duck-typing
16 \item High-level
17 \item Multi-paradigm
18 \item \ldots
19 \end{itemize}
20 \end{frame}
21
22 \begin{frame}[fragile]
23 \frametitle{How to start}
24 \framesubtitle{Interpreter}
25 \begin{minted}[breaklines=true]{pycon}
26 Python 3.5.1 (default, Dec 7 2015, 12:58:09)
27 [GCC 5.2.0] on linux
28 Type "help", "copyright", "credits" or "license" for more
29 information.
30 >>> print('Hello world!')
31 Hello world!
32 >>> i = 1972
33 >>> print(str(i/46) + ' hoi')
34 42.869565217391305 hoi
35 \end{minted}
36 \end{frame}
37
38 \begin{frame}[fragile]
39 \frametitle{How to start}
40 \framesubtitle{Source files}
41 \begin{minted}{python}
42 #!/usr/bin/env python3
43 # -*- coding: utf-8 -*-
44
45 print('hello world')
46 i = 1972
47 print(str(i/46) + ' hoi')
48 \end{minted}
49 \end{frame}
50
51 \section{Basics}
52 \begin{frame}[fragile]
53 \frametitle{Built-in types}
54 \begin{tabular}{ll}
55 \mintinline{python}{bool} & \mintinline{python}{True, False}\\
56 \mintinline{python}{int} & \mintinline{python}{1, -4, 999}\\
57 \mintinline{python}{complex} & \mintinline{python}{4j+1, j}\\
58 \mintinline{python}{float} & \mintinline{python}
59 {1.0, 4.5, 5e9, float('NaN'), float('inf')}\\
60 \mintinline{python}{str} & \mintinline{python}
61 {'hi', "hi", '"', "'", """hi""", "\n\"\t", '\"'}\\
62 \mintinline{python}{list} & \mintinline{python}
63 {[], ..., [1, 2, 3], ['a', 42], [[], [1]]}\\
64 \mintinline{python}{tuple} & \mintinline{python}
65 {(1,), (1,2), (1, 'a', True), ((4, 3), 4)}\\
66 \mintinline{python}{dict} & \mintinline{python}
67 {{1: 'a', 2: 'b'}, {"hi": 42, "test": {}}, {}}\\
68 \mintinline{python}{set} & \mintinline{python}
69 {{1, 2}, {"hi", "a"}, set()}\\
70 Others & \mintinline{python}
71 {range, bytes, bytearray, memoryview, frozenset}\\
72 Special & \mintinline{python}
73 {type, None, ..., NotImplemented}\\
74 \end{tabular}
75 \end{frame}
76
77 \begin{frame}[fragile]
78 \frametitle{Basictypes: Operators}
79 \begin{block}{operators}
80 \begin{itemize}
81 \item Numbers: \mintinline{python}{+ - / * // % @ **}
82 \item Comparison: \mintinline{python}{< <= > >= == !=}
83 \item Boolean: \mintinline{python}{and or not}
84 \item Bitwise: \mintinline{python}{& | ^ ~ << >>}
85 \item List/Dictionary: \mintinline{python}{[i] [i:j] in}
86 \item In place: \mintinline{python}{*= += ...}
87 \item Special: \mintinline{python}{is}
88 \end{itemize}
89 \end{block}
90 \end{frame}
91
92 \section{Control flow}
93 \subsection{If, then, else}
94 \begin{frame}[fragile]
95 \frametitle{Conditional execution}
96 \framesubtitle{\texttt{fizzbuzz.py}}
97 \begin{minted}{python}
98 #!/usr/bin/env python3
99
100 i = int(input('Enter a number: '))
101 if i % 3 == 0 and i % 5 == 0:
102 print('fizzbuzz')
103 elif i % 3 == 0:
104 print('buzz')
105 elif i % 5 == 0:
106 print('fizz')
107 else:
108 print(i)
109 \end{minted}
110 \end{frame}
111
112 \begin{frame}[fragile]
113 \frametitle{Conditional execution 2}
114 \framesubtitle{\texttt{fizzbuzz.py}}
115 \begin{minted}{shell-session}
116 frobnicator@frobmachine~$ python fizzbuzz.py
117 Enter a number: 42
118 buzz
119 frobnicator@frobmachine~$ python fizzbuzz.py
120 Enter a number: 15
121 fizzbuzz
122 frobnicator@frobmachine~$ python fizzbuzz.py
123 Enter a number: 43
124 43
125 frobnicator@frobmachine~$ python fizzbuzz.py
126 Enter a number: 9
127 fizz
128 \end{minted}
129 \end{frame}
130
131 \subsection{While, for}
132 \begin{frame}[fragile]
133 \frametitle{Looping}
134 \begin{minted}{python}
135 ls = ["hello", "world", "!"]
136
137 # Pythonic for loop
138 for item in ls:
139 print(ls)
140
141 # C style for loop
142 for i in range(0, len(ls)):
143 print(ls[i])
144
145 # While loop
146 i = 10
147 while i >= 0:
148 print(i);
149 print('fire!')
150 \end{minted}
151 \end{frame}
152
153 \begin{frame}[fragile]
154 \frametitle{Looping: Escape rope}
155 \begin{minted}{python}
156 # 100.000st prime, 100.001st prime, and a pseudoprime
157 numbers = [1299709, 1299721, 1299709*1299721]
158 for n in numbers:
159 for x in range(2, n):
160 if n % x == 0:
161 print(n, 'equals', x, '*', n//x)
162 break
163 else:
164 print(n, 'is a prime number')
165
166 # 1299709 is a prime number
167 # 1299721 is a prime number
168 # 1689259081189 equals 1299709 * 1299721
169
170 # pass, continue
171 \end{minted}
172 \end{frame}
173
174 \subsection{Functions}
175 \begin{frame}[fragile]
176 \frametitle{Functions}
177
178 \end{frame}
179
180 \begin{frame}[fragile]
181 \frametitle{Functions: Advanced arguments}
182
183 \end{frame}
184
185 \section{Datastructures}
186
187 \section{Input/Output}
188
189 \section{Errors}
190
191 \section{Standard Library}
192 \end{document}