Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
t20100 committed Apr 17, 2019
2 parents 31734af + ea74893 commit cd1dd3d
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 740 deletions.
44 changes: 40 additions & 4 deletions python/python/0_Introduction.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Introduction to Python \n",
"\n",
"## Provided by the Data Analysis Unit team\n",
"\n",
"Those slides can be found at:\n",
"\n",
"https://github.com/silx-kit/silx-training/blob/master/python/python/0_Introduction.ipynb"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Mutual introduction of trainers and trainees:\n",
"\n",
"* Activities\n",
"* Background in programming (C, Fortran, matlab ?)\n",
"* Expectation for the day"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -138,8 +170,12 @@
"source": [
"\n",
"- Portable\n",
" - Runs on any computer you may have access to\n",
"\n"
" - Runs on any computer you may have access to:\n",
" - Supercomputers\n",
" - Servers\n",
" - Desktop computers\n",
" - Smartphones\n",
" - Microcontrolers ([micropython](https://micropython.org/))"
]
},
{
Expand Down Expand Up @@ -255,7 +291,7 @@
"## Why Python for data-analysis ?\n",
"\n",
"- Python can be learned in a couple of days\n",
"- Ideal for prototyping\n",
"- JuPyteR is ideal for prototyping\n",
"- Free alternative to Matlab\n",
"- It runs everywhere\n",
"- Batteries are included\n",
Expand Down Expand Up @@ -497,7 +533,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.7.2"
}
},
"nbformat": 4,
Expand Down
33 changes: 21 additions & 12 deletions python/python/1_Definitions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
"* `int` variable length integers,\n",
"* `float` double precision floating point numbers, \n",
"* `complex` composed of two floats for *real* and *imag* part, \n",
"* `bool` boolean which can be only True or False. \n",
"* `None` which is the equivalent of *NULL* or *nil*\n",
"* `str` unicode character strings,\n"
"* `str` unicode character strings,\n",
"* `bool` boolean which can be only True or False\n",
"* `None`, actually `NoneType` but there is only one, equivalent of *NULL* or *nil*"
]
},
{
Expand Down Expand Up @@ -147,7 +147,7 @@
},
"outputs": [],
"source": [
"# int have infinite precision\n",
"# integers have an infinite precision in Python\n",
"11**300"
]
},
Expand Down Expand Up @@ -591,7 +591,7 @@
},
"outputs": [],
"source": [
"print([1,2,3])\n",
"print([1,2,3]) \n",
"digits = list(range(10))\n",
"print(digits)"
]
Expand Down Expand Up @@ -1332,7 +1332,7 @@
}
},
"source": [
"**Warning:** This is very error prone when manipulating any mutable objects."
"**Warning:** This is very error prone when manipulating **any** mutable objects."
]
},
{
Expand Down Expand Up @@ -1397,7 +1397,7 @@
"```\n",
"\n",
"- Clearly indicates the beginning of a block\n",
"- Coding style is mostly uniform. Use **4 spaces**, never <tabs>\n",
"- Coding style is mostly uniform. Use **4 spaces**, never **< tabs >**\n",
"- Code structure is much more readable and clear.\n",
"\n"
]
Expand Down Expand Up @@ -1433,7 +1433,16 @@
"b = 2\n",
"c = 1\n",
"q2 = b * b - 4.0 * a * c\n",
"print(\"Determinant is \", q2)\n",
"print(\"Determinant is \", q2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import math\n",
"if q2 < 0:\n",
" print(\"No real solution\")\n",
"elif q2 > 0:\n",
Expand Down Expand Up @@ -1486,7 +1495,7 @@
},
"outputs": [],
"source": [
"for idx, food in enumerate(ingredients[::-1]):\n",
"for idx, food in enumerate(ingredients[-1::-1]):\n",
" print(\"%s is number %d in my top 5 of foods\" % (food, len(ingredients)- idx))"
]
},
Expand Down Expand Up @@ -1643,9 +1652,9 @@
},
"outputs": [],
"source": [
"%%time\n",
"%%timeit\n",
"# Sorry this exercise is not solved\n",
"print([0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987])"
"[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]"
]
},
{
Expand Down Expand Up @@ -1692,7 +1701,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.7.2"
}
},
"nbformat": 4,
Expand Down
7 changes: 4 additions & 3 deletions python/python/2_Functions_Classes_Modules.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
"## Function parameters:\n",
"\n",
"* Default values for a parameter can be given after an `=` sign\n",
"* All parameters can be seen as a list using the `*args` notation where args contains all arguments\n",
"* All parameters can be seen as a tuple using the `*args` notation where args contains all arguments\n",
"* All parameters can be seen as a dictionnary using the `**kwargs` notation\n"
]
},
Expand Down Expand Up @@ -208,7 +208,7 @@
"outputs": [],
"source": [
" def anyarg_function1(*unamedargs):\n",
" print(\"I got those arguments in a list:\")\n",
" print(\"I got those arguments in a tuple:\")\n",
" print(unamedargs)\n",
"\n",
"anyarg_function1()\n",
Expand Down Expand Up @@ -248,7 +248,7 @@
" print('r param = %s' % r)\n",
" print('n param = %s' % n)\n",
" if len(arglist) > 0:\n",
" print('got %s unnamed argument ' %len(arglist))\n",
" print('got %s unnamed argument ' % len(arglist))\n",
" for arg in arglist:\n",
" print('- %s' % arg)\n",
" if len(argdict) > 0:\n",
Expand Down Expand Up @@ -632,6 +632,7 @@
"* Specify the name of the interpretor on first line of the file like `#!/usr/bin/env python`\n",
"* Make the script executable using `chmod +x filename`\n",
"* Define a **main** section with `if __name__ == \"__main__\":`\n",
"\n",
" → this block will be executed only when the script is executed. Not when imported"
]
},
Expand Down
Loading

0 comments on commit cd1dd3d

Please sign in to comment.