-
Notifications
You must be signed in to change notification settings - Fork 7
/
examples.html
37 lines (25 loc) · 1.13 KB
/
examples.html
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
$title mypy - Examples$
$keywords mypy example, mypy code$
$description Mypy example programs, with separate dynamically and statically typed variants.$
<div id="wide">
<h1 class="first">Mypy Examples</h1>
<p>Here are some mypy example programs. Each example has dynamically typed
Python/mypy code and equivalent statically typed mypy code side by
side. Every program is still valid Python 3.x.
All differences between the variants are
<span class="hili">highlighted</span>.
<h2>Word frequencies with a dictionary</h2>
$example(wordfreq)$
<p>In this example we add an explicit type declaration for the variable d, as
it is not obvious from the local context.
<h2>Simple class</h2>
$example(bank)$
<p>In this example we chose to use integers to represent balance.
This would be fine in a game, for example, but in other applications a
different type would make more sense.
<p>This example was adapted from the
<a href="http://wiki.python.org/moin/SimplePrograms">Python wiki</a> (with
the standard Python license).
<h2>Prime number sieve with generators</h2>
$example(sieve2)$
<p>Like the bank account example, this was adapted from the Python wiki.