added tuple
[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{Basictypes}
54 \begin{block}{types}
55 \begin{tabular}{ll}
56 \mintinline{python}{bool} & \mintinline{python}{True, False}\\
57 \mintinline{python}{int} & \mintinline{python}{1, -4, 999}\\
58 \mintinline{python}{complex} & \mintinline{python}{4j+1, j}\\
59 \mintinline{python}{float} & \mintinline{python}
60 {1.0, 4.5, 5e9, float('NaN'), float('inf')}\\
61 \mintinline{python}{str} & \mintinline{python}
62 {'hi', "hi", '"', "'", """hi"""}\\
63 \mintinline{python}{list} & \mintinline{python}
64 {[], ..., [1, 2, 3], ['a', 42], [[], [1]]}\\
65 \mintinline{python}{tuple} & \mintinline{python}
66 {(1,), (1,2), (1, 'a', True), ((4, 3), 4)}
67 \end{tabular}
68 \end{block}
69 \begin{block}{operators}
70 \begin{itemize}
71 \item Numbers: \mintinline{python}{+ - / * // % @ **}
72 \item Comparison: \mintinline{python}{< <= > >= == != is}
73 \item Boolean: \mintinline{python}{and or not}
74 \item Bitwise: \mintinline{python}{& | ^ ~ << >>}
75 \item List: \mintinline{python}{[i] [i:j] in}
76 \item In place: \mintinline{python}{*= += ...}
77 \end{itemize}
78 \end{block}
79 \end{frame}
80
81 \section{Control flow}
82 \subsection{If, then, else}
83 \begin{frame}[fragile]
84 \frametitle{Conditional execution}
85 \framesubtitle{\texttt{fizzbuzz.py}}
86 \begin{minted}{python}
87 #!/usr/bin/env python3
88
89 i = int(input('Enter a number: '))
90 if i % 3 == 0 and i % 5 == 0:
91 print('fizzbuzz')
92 elif i % 3 == 0:
93 print('buzz')
94 elif i % 5 == 0:
95 print('fizz')
96 else:
97 print(i)
98 \end{minted}
99 \end{frame}
100
101 \begin{frame}[fragile]
102 \frametitle{Conditional execution 2}
103 \framesubtitle{\texttt{fizzbuzz.py}}
104 \begin{minted}{shell-session}
105 frobnicator@frobmachine~$ python fizzbuzz.py
106 Enter a number: 42
107 buzz
108 frobnicator@frobmachine~$ python fizzbuzz.py
109 Enter a number: 15
110 fizzbuzz
111 frobnicator@frobmachine~$ python fizzbuzz.py
112 Enter a number: 43
113 43
114 frobnicator@frobmachine~$ python fizzbuzz.py
115 Enter a number: 9
116 fizz
117 \end{minted}
118 \end{frame}
119
120 \subsection{While, for}
121 \begin{frame}[fragile]
122 \frametitle{Looping}
123 \begin{minted}{python}
124 ls = ["hello", "world", "!"]
125
126 # Pythonic for loop
127 for item in ls:
128 print(ls)
129
130 # C style for loop
131 for i in range(0, len(ls)):
132 print(ls[i])
133
134 # While loop
135 i = 10
136 while i >= 0:
137 print(i);
138 print('fire!')
139 \end{minted}
140 \end{frame}
141
142 \begin{frame}[fragile]
143 \frametitle{Looping: Escape rope}
144 \begin{minted}{python}
145 # 100.000st prime, 100.001st prime, and a pseudoprime
146 numbers = [1299709, 1299721, 1299709*1299721]
147 for n in numbers:
148 for x in range(2, n):
149 if n % x == 0:
150 print(n, 'equals', x, '*', n//x)
151 break
152 else:
153 print(n, 'is a prime number')
154
155 # 1299709 is a prime number
156 # 1299721 is a prime number
157 # 1689259081189 equals 1299709 * 1299721
158
159 # pass, continue
160 \end{minted}
161 \end{frame}
162
163 \subsection{Functions}
164 \begin{frame}[fragile]
165 \frametitle{Functions}
166
167 \end{frame}
168
169 \begin{frame}[fragile]
170 \frametitle{Functions: Advanced arguments}
171
172 \end{frame}
173
174 \section{Datastructures}
175
176 \section{Input/Output}
177
178 \section{Errors}
179
180 \section{Standard Library}
181 \end{document}