Skip to content

Commit cd1dd3d

Browse files
committed
2 parents 31734af + ea74893 commit cd1dd3d

8 files changed

Lines changed: 65 additions & 740 deletions

File tree

python/python/0_Introduction.ipynb

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"slideshow": {
7+
"slide_type": "slide"
8+
}
9+
},
10+
"source": [
11+
"# Introduction to Python \n",
12+
"\n",
13+
"## Provided by the Data Analysis Unit team\n",
14+
"\n",
15+
"Those slides can be found at:\n",
16+
"\n",
17+
"https://github.com/silx-kit/silx-training/blob/master/python/python/0_Introduction.ipynb"
18+
]
19+
},
20+
{
21+
"cell_type": "markdown",
22+
"metadata": {
23+
"slideshow": {
24+
"slide_type": "subslide"
25+
}
26+
},
27+
"source": [
28+
"Mutual introduction of trainers and trainees:\n",
29+
"\n",
30+
"* Activities\n",
31+
"* Background in programming (C, Fortran, matlab ?)\n",
32+
"* Expectation for the day"
33+
]
34+
},
335
{
436
"cell_type": "markdown",
537
"metadata": {
@@ -138,8 +170,12 @@
138170
"source": [
139171
"\n",
140172
"- Portable\n",
141-
" - Runs on any computer you may have access to\n",
142-
"\n"
173+
" - Runs on any computer you may have access to:\n",
174+
" - Supercomputers\n",
175+
" - Servers\n",
176+
" - Desktop computers\n",
177+
" - Smartphones\n",
178+
" - Microcontrolers ([micropython](https://micropython.org/))"
143179
]
144180
},
145181
{
@@ -255,7 +291,7 @@
255291
"## Why Python for data-analysis ?\n",
256292
"\n",
257293
"- Python can be learned in a couple of days\n",
258-
"- Ideal for prototyping\n",
294+
"- JuPyteR is ideal for prototyping\n",
259295
"- Free alternative to Matlab\n",
260296
"- It runs everywhere\n",
261297
"- Batteries are included\n",
@@ -497,7 +533,7 @@
497533
"name": "python",
498534
"nbconvert_exporter": "python",
499535
"pygments_lexer": "ipython3",
500-
"version": "3.5.2"
536+
"version": "3.7.2"
501537
}
502538
},
503539
"nbformat": 4,

python/python/1_Definitions.ipynb

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
"* `int` variable length integers,\n",
3434
"* `float` double precision floating point numbers, \n",
3535
"* `complex` composed of two floats for *real* and *imag* part, \n",
36-
"* `bool` boolean which can be only True or False. \n",
37-
"* `None` which is the equivalent of *NULL* or *nil*\n",
38-
"* `str` unicode character strings,\n"
36+
"* `str` unicode character strings,\n",
37+
"* `bool` boolean which can be only True or False\n",
38+
"* `None`, actually `NoneType` but there is only one, equivalent of *NULL* or *nil*"
3939
]
4040
},
4141
{
@@ -147,7 +147,7 @@
147147
},
148148
"outputs": [],
149149
"source": [
150-
"# int have infinite precision\n",
150+
"# integers have an infinite precision in Python\n",
151151
"11**300"
152152
]
153153
},
@@ -591,7 +591,7 @@
591591
},
592592
"outputs": [],
593593
"source": [
594-
"print([1,2,3])\n",
594+
"print([1,2,3]) \n",
595595
"digits = list(range(10))\n",
596596
"print(digits)"
597597
]
@@ -1332,7 +1332,7 @@
13321332
}
13331333
},
13341334
"source": [
1335-
"**Warning:** This is very error prone when manipulating any mutable objects."
1335+
"**Warning:** This is very error prone when manipulating **any** mutable objects."
13361336
]
13371337
},
13381338
{
@@ -1397,7 +1397,7 @@
13971397
"```\n",
13981398
"\n",
13991399
"- Clearly indicates the beginning of a block\n",
1400-
"- Coding style is mostly uniform. Use **4 spaces**, never <tabs>\n",
1400+
"- Coding style is mostly uniform. Use **4 spaces**, never **< tabs >**\n",
14011401
"- Code structure is much more readable and clear.\n",
14021402
"\n"
14031403
]
@@ -1433,7 +1433,16 @@
14331433
"b = 2\n",
14341434
"c = 1\n",
14351435
"q2 = b * b - 4.0 * a * c\n",
1436-
"print(\"Determinant is \", q2)\n",
1436+
"print(\"Determinant is \", q2)"
1437+
]
1438+
},
1439+
{
1440+
"cell_type": "code",
1441+
"execution_count": null,
1442+
"metadata": {},
1443+
"outputs": [],
1444+
"source": [
1445+
"import math\n",
14371446
"if q2 < 0:\n",
14381447
" print(\"No real solution\")\n",
14391448
"elif q2 > 0:\n",
@@ -1486,7 +1495,7 @@
14861495
},
14871496
"outputs": [],
14881497
"source": [
1489-
"for idx, food in enumerate(ingredients[::-1]):\n",
1498+
"for idx, food in enumerate(ingredients[-1::-1]):\n",
14901499
" print(\"%s is number %d in my top 5 of foods\" % (food, len(ingredients)- idx))"
14911500
]
14921501
},
@@ -1643,9 +1652,9 @@
16431652
},
16441653
"outputs": [],
16451654
"source": [
1646-
"%%time\n",
1655+
"%%timeit\n",
16471656
"# Sorry this exercise is not solved\n",
1648-
"print([0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987])"
1657+
"[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]"
16491658
]
16501659
},
16511660
{
@@ -1692,7 +1701,7 @@
16921701
"name": "python",
16931702
"nbconvert_exporter": "python",
16941703
"pygments_lexer": "ipython3",
1695-
"version": "3.5.2"
1704+
"version": "3.7.2"
16961705
}
16971706
},
16981707
"nbformat": 4,

python/python/2_Functions_Classes_Modules.ipynb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
"## Function parameters:\n",
175175
"\n",
176176
"* Default values for a parameter can be given after an `=` sign\n",
177-
"* All parameters can be seen as a list using the `*args` notation where args contains all arguments\n",
177+
"* All parameters can be seen as a tuple using the `*args` notation where args contains all arguments\n",
178178
"* All parameters can be seen as a dictionnary using the `**kwargs` notation\n"
179179
]
180180
},
@@ -208,7 +208,7 @@
208208
"outputs": [],
209209
"source": [
210210
" def anyarg_function1(*unamedargs):\n",
211-
" print(\"I got those arguments in a list:\")\n",
211+
" print(\"I got those arguments in a tuple:\")\n",
212212
" print(unamedargs)\n",
213213
"\n",
214214
"anyarg_function1()\n",
@@ -248,7 +248,7 @@
248248
" print('r param = %s' % r)\n",
249249
" print('n param = %s' % n)\n",
250250
" if len(arglist) > 0:\n",
251-
" print('got %s unnamed argument ' %len(arglist))\n",
251+
" print('got %s unnamed argument ' % len(arglist))\n",
252252
" for arg in arglist:\n",
253253
" print('- %s' % arg)\n",
254254
" if len(argdict) > 0:\n",
@@ -632,6 +632,7 @@
632632
"* Specify the name of the interpretor on first line of the file like `#!/usr/bin/env python`\n",
633633
"* Make the script executable using `chmod +x filename`\n",
634634
"* Define a **main** section with `if __name__ == \"__main__\":`\n",
635+
"\n",
635636
" → this block will be executed only when the script is executed. Not when imported"
636637
]
637638
},

0 commit comments

Comments
 (0)