Skip to content
Snippets Groups Projects
Commit 239762f2 authored by jkvis's avatar jkvis
Browse files

XMerge branch 'master' of git.lumc.nl:courses/programming-course

parents 12fac270 3a94007d
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,7 @@ be done in your own time (i.e., during the afternoons). ...@@ -23,7 +23,7 @@ be done in your own time (i.e., during the afternoons).
Please note that the above mentioned date and location are subject to change. Please note that the above mentioned date and location are subject to change.
Program Program and Materials
------- -------
- Mornings: presentations. - Mornings: presentations.
...@@ -31,13 +31,13 @@ Program ...@@ -31,13 +31,13 @@ Program
| Day | Time | Lesson | Teacher | | Day | Time | Lesson | Teacher |
|-----------------|-------|------------------------------------ |----------| |-----------------|-------|------------------------------------ |----------|
| Monday, 18/9 | 9-10 | Welcome, Introduction to Python (1) | Mihai | | Monday, 18/9 | 9-10 | [Welcome][lesson_01], [Introduction to Python (1)][lesson_02_01] | Mihai |
| | 10-11 | Introduction to Python (2) | Jeroen | | | 10-11 | [Introduction to Python (2)][lesson_02_02] | Jeroen |
| | 11-12 | Introduction to Python (3) | Mihai | | | 11-12 | [Introduction to Python (3)][lesson_02_03] | Mihai |
| | 12-13 | Practical help | | | | 12-13 | Practical help | |
| Tuesday, 19/9 | 9-10 | Assignments review | | | Tuesday, 19/9 | 9-10 | Assignments review | |
| | 10-11 | More Python Goodness (1) | Mihai | | | 10-11 | [More Python Goodness (1)][lesson_03_01] | Mihai |
| | 11-12 | More Python Goodness (2) | Mihai | | | 11-12 | [More Python Goodness (2)][lesson_03_02] | Mihai |
| | 12-13 | IPython Notebook | Mark | | | 12-13 | IPython Notebook | Mark |
| Wednesday, 20/9 | 9-10 | Assignments review | | | Wednesday, 20/9 | 9-10 | Assignments review | |
| | 10-11 | Data manipulation (NumPy, Pandas) | Mark | | | 10-11 | Data manipulation (NumPy, Pandas) | Mark |
...@@ -48,29 +48,22 @@ Program ...@@ -48,29 +48,22 @@ Program
| | 11-12 | Biopython | Guy | | | 11-12 | Biopython | Guy |
| | 12-13 | Putting everything together | Jeroen | | | 12-13 | Putting everything together | Jeroen |
Some of the lessons are slideshows, whereas others are just
notebooks we scroll through during class. The links above are all one-page
static renderings on [IPython Notebook Viewer](http://nbviewer.ipython.org/).
Materials
---------
The top-level directory contains materials for the following lessons: Assignments
-------
- [First day](https://classroom.github.com/a/QU2iPYKn).
1. Welcome ([slides][lesson_01])
2. Introduction to Python ([slides 1][lesson_02_01], [slides 2][lesson_02_02],
[slides 3][lesson_02_03])
3. More Python Goodness ([notebook 1][lesson_03_01], [notebook 2][lesson_03_02])
4. Working with NumPy arrays ([slides][lesson_04])
5. IPython Notebook ([notebook][lesson_05])
6. Plotting with matplotlib ([notebook][lesson_06])
7. Painting Pandas ([slides][lesson_07])
8. Object-oriented programming ([slides][lesson_08])
9. A sip of Biopython ([notebook 1][lesson_09_01], [notebook 2][lesson_09_02])
[lesson_01]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/introduction/01_welcome.ipynb [lesson_01]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/introduction/01_welcome.ipynb
[lesson_02_01]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/02%20-%20Introduction%20to%20Python%20(1).ipynb [lesson_02_01]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/introduction/02_introduction_to_python_1.ipynb
[lesson_02_02]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/02%20-%20Introduction%20to%20Python%20(2).ipynb [lesson_02_02]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/introduction/02_introduction_to_python_2.ipynb
[lesson_02_03]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/02%20-%20Introduction%20to%20Python%20(3).ipynb [lesson_02_03]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/introduction/02_introduction_to_python_3.ipynb
[lesson_03_01]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/03%20-%20More%20Python%20goodness%20(1).ipynb [lesson_03_01]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/more_python/03_more_python_goodness_1.ipynb
[lesson_03_02]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/03%20-%20More%20Python%20goodness%20(2).ipynb [lesson_03_02]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/more_python/03_more_python_goodness_2.ipynb
[lesson_04]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/04%20-%20Working%20with%20NumPy%20arrays.ipynb [lesson_04]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/04%20-%20Working%20with%20NumPy%20arrays.ipynb
[lesson_05]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/05%20-%20IPython%20Notebook.ipynb [lesson_05]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/05%20-%20IPython%20Notebook.ipynb
[lesson_06]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/06%20-%20Plotting%20with%20matplotlib.ipynb [lesson_06]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/06%20-%20Plotting%20with%20matplotlib.ipynb
...@@ -79,17 +72,10 @@ The top-level directory contains materials for the following lessons: ...@@ -79,17 +72,10 @@ The top-level directory contains materials for the following lessons:
[lesson_09_01]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/09%20-%20A%20sip%20of%20Biopython%20(1).ipynb [lesson_09_01]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/09%20-%20A%20sip%20of%20Biopython%20(1).ipynb
[lesson_09_02]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/09%20-%20A%20sip%20of%20Biopython%20(2).ipynb [lesson_09_02]: http://nbviewer.ipython.org/urls/git.lumc.nl/courses/programming-course/raw/master/09%20-%20A%20sip%20of%20Biopython%20(2).ipynb
As indicated, some of the lessons are slideshows, whereas others are just
notebooks we scroll through during class. The links above are all one-page
static renderings on [IPython Notebook Viewer](http://nbviewer.ipython.org/).
We also have a
[repository with material for the assignments](https://git.lumc.nl/courses/programming-course-assignments).
Software installation Software installation
--------------------- ---------------------
See the instructions in [INSTALL.md](/INSTALL.md). See the instructions [here](https://docs.anaconda.com/anaconda/install/).
Notebooks Notebooks
--------- ---------
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
viewBox="0 0 1052.4 368.09"
id="svg2"
inkscape:version="0.91 r13725"
sodipodi:docname="python_logo.svg"
width="1052.4"
height="368.09003">
<metadata
id="metadata14">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs12" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="2495"
inkscape:window-height="1416"
id="namedview10"
showgrid="false"
inkscape:zoom="0.8009039"
inkscape:cx="589.44223"
inkscape:cy="227.21656"
inkscape:window-x="65"
inkscape:window-y="24"
inkscape:window-maximized="1"
inkscape:current-layer="svg2" />
<g
transform="translate(324.63321,-501.97596)"
id="g4">
<path
d="m 524.02,846.67 c -33.839,-1.2297 -54.784,-11.264 -60.113,-28.8 l -0.6194,-2.0382 -0.0869,-34.378 c -0.0994,-39.346 -0.0645,-40.143 2.0299,-46.408 3.8218,-11.432 12.859,-18.803 26.993,-22.016 l 3.1253,-0.71039 38.862,-0.17214 c 27.843,-0.12334 39.388,-0.26278 40.716,-0.49179 7.7818,-1.3418 12.887,-3.3508 17.679,-6.9578 5.7253,-4.309 10.451,-11.685 12.563,-19.607 1.5862,-5.9503 1.5436,-5.3002 1.715,-26.202 l 0.15935,-19.431 27.992,0 2.7176,0.75892 c 14.561,4.0662 25.133,17.862 29.633,38.671 1.7311,8.0037 1.7492,8.2998 1.7524,28.718 0.003,19.87 -0.006,20.044 -1.3943,26.562 -1.3645,6.4064 -3.1506,11.619 -5.8196,16.985 -5.3828,10.822 -13.32,18.146 -23.357,21.553 -5.7335,1.9464 -0.93423,1.7836 -57.342,1.9449 l -50.82,0.14528 0,9.24 33.699,0.13588 33.699,0.13589 0.13588,16.578 c 0.0747,9.1177 0.0421,17.36 -0.0725,18.316 -0.27725,2.3131 -1.2585,5.0581 -2.6625,7.4485 -1.4458,2.4616 -5.8352,6.8642 -8.8149,8.8417 -9.0505,6.0063 -22.849,9.6675 -41.036,10.888 -6.1192,0.41068 -14.785,0.52882 -21.333,0.29086 z m 46.743,-21.481 c 6.4954,-1.053 11.145,-7.4099 10.074,-13.773 -0.88336,-5.2488 -4.9357,-9.3086 -10.155,-10.173 -7.9672,-1.3202 -15.213,5.9958 -13.795,13.929 1.0313,5.7708 5.6585,9.8336 11.701,10.274 0.2242,0.0163 1.2026,-0.0992 2.1741,-0.25667 z m -144.8,-49.035 c -7.6439,-1.3898 -15.171,-6.0227 -20.491,-12.611 -10.075,-12.479 -15.162,-33.284 -14.523,-59.406 0.3979,-16.278 2.8315,-28.362 7.782,-38.641 6.3813,-13.25 15.916,-21.108 28.787,-23.724 2.8193,-0.57313 2.9606,-0.57462 52.615,-0.55479 27.384,0.0109 49.989,-0.0572 50.235,-0.1514 0.38956,-0.14949 0.44634,-0.75521 0.44634,-4.7622 0,-2.525 -0.0306,-4.6203 -0.0679,-4.6562 -0.0374,-0.0359 -15.232,-0.12763 -33.767,-0.20383 l -33.699,-0.13854 -0.07,-17.514 c -0.0766,-19.183 -0.092,-18.96 1.5503,-22.483 5.6933,-12.213 22.465,-19.633 49.339,-21.829 1.9431,-0.1588 7.2017,-0.36064 11.686,-0.44852 29.753,-0.58311 51.579,4.8575 63.052,15.717 1.271,1.2031 2.9273,2.9988 3.6807,3.9906 1.7132,2.255 3.8458,6.5603 4.6624,9.4125 l 0.62243,2.1741 0,36.145 c 0,33.739 -0.0327,36.316 -0.49158,38.726 -0.59212,3.1098 -2.0144,7.4792 -3.1997,9.8301 -4.1039,8.1393 -11.665,14.003 -21.689,16.82 -6.5086,1.8288 -3.5525,1.7086 -46.637,1.8956 -42.787,0.18564 -40.201,0.086 -46.2,1.7812 -11.651,3.2927 -20.21,12.367 -23.687,25.113 -1.5631,5.7299 -1.5284,5.1946 -1.6996,26.225 l -0.15925,19.567 -13.045,0.0447 c -9.8474,0.0338 -13.532,-0.0439 -15.034,-0.31707 z m 71.232,-162.58 c 4.9456,-2.3234 7.924,-7.7698 7.0286,-12.853 -0.82592,-4.6888 -4.0455,-8.4308 -8.4148,-9.7804 -6.983,-2.1568 -14.269,2.2939 -15.558,9.5032 -1.0478,5.8633 2.3432,11.571 8.0784,13.598 1.2817,0.45295 2.1059,0.54476 4.303,0.47938 2.3937,-0.0712 2.9375,-0.18417 4.5622,-0.94747 z"
id="path6"
inkscape:connector-curvature="0"
style="fill:#fed142" />
<path
d="m 425.96,776.15 c -7.6439,-1.3898 -15.171,-6.0227 -20.491,-12.611 -10.075,-12.479 -15.162,-33.284 -14.523,-59.406 0.3979,-16.278 2.8315,-28.362 7.782,-38.641 6.3813,-13.25 15.916,-21.108 28.787,-23.724 2.8193,-0.57313 2.9606,-0.57462 52.615,-0.55479 27.384,0.0109 49.989,-0.0572 50.235,-0.1514 0.38956,-0.14949 0.44634,-0.75521 0.44634,-4.7622 0,-2.525 -0.0306,-4.6203 -0.0679,-4.6562 -0.0374,-0.0359 -15.232,-0.12763 -33.767,-0.20383 l -33.699,-0.13854 -0.07,-17.514 c -0.0766,-19.183 -0.092,-18.96 1.5503,-22.483 5.6933,-12.213 22.465,-19.633 49.339,-21.829 1.9431,-0.1588 7.2017,-0.36064 11.686,-0.44852 29.753,-0.58311 51.579,4.8575 63.052,15.717 1.271,1.2031 2.9273,2.9988 3.6807,3.9906 1.7132,2.255 3.8458,6.5603 4.6624,9.4125 l 0.62243,2.1741 0,36.145 c 0,33.739 -0.0327,36.316 -0.49158,38.726 -0.59212,3.1098 -2.0144,7.4792 -3.1997,9.8301 -4.1039,8.1393 -11.665,14.003 -21.689,16.82 -6.5086,1.8288 -3.5525,1.7086 -46.637,1.8956 -42.787,0.18564 -40.201,0.086 -46.2,1.7812 -11.651,3.2927 -20.21,12.367 -23.687,25.113 -1.5631,5.7299 -1.5284,5.1946 -1.6996,26.225 l -0.15925,19.567 -13.045,0.0447 c -9.8474,0.0338 -13.532,-0.0439 -15.034,-0.31707 z m 71.232,-162.58 c 4.9456,-2.3234 7.924,-7.7698 7.0286,-12.853 -0.82592,-4.6888 -4.0455,-8.4308 -8.4148,-9.7804 -6.983,-2.1568 -14.269,2.2939 -15.558,9.5032 -1.0478,5.8633 2.3432,11.571 8.0784,13.598 1.2817,0.45295 2.1059,0.54476 4.303,0.47938 2.3937,-0.0712 2.9375,-0.18417 4.5622,-0.94747 z"
id="path8"
inkscape:connector-curvature="0"
style="fill:#3571a3" />
</g>
</svg>
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
<span style="font-size: 200%">Programming in Python</span> <span style="font-size: 200%">Programming in Python</span>
=== ===
<br> <br>
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
About the course About the course
=== ===
* Aimed at PhD students, Postdocs, researchers, analysts, ... * Aimed at PhD students, Postdocs, researchers, analysts, ...
* Programming as a tool to do your research. * Focus on:
* Slightly focussed on bioinformatics. - Basic understanding of Python.
- Programming as a tool to do your research.
- Slightly biased on bioinformatics.
**Note:** This is its third session. **Note:** This is its third session.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Hands on!
===
**Programming is fun!**
* You only learn programming by doing it.
* Lecture format:
- Blended teaching + exercising.
* Have your laptop open during the lessons.
* Repeat the code from the slides, play around with it.
* Do the session exercises.
* There will be a few assignments to submit.
%% Cell type:markdown id: tags:
Teachers Teachers
=== ===
* Jeroen Laros<br> * Jeroen Laros<br>
[j.f.j.laros@lumc.nl](mailto:j.f.j.laros@lumc.nl) [j.f.j.laros@lumc.nl](mailto:j.f.j.laros@lumc.nl)
* Mihai Lefter<br> * Mihai Lefter<br>
[m.lefter@lumc.nl](mailto:m.lefter@lumc.nl) [m.lefter@lumc.nl](mailto:m.lefter@lumc.nl)
* Jonathan Vis<br> * Jonathan Vis<br>
[j.k.vis@lumc.nl](mailto:j.k.vis@lumc.nl) [j.k.vis@lumc.nl](mailto:j.k.vis@lumc.nl)
* Mark Santcroos<br> * Mark Santcroos<br>
[m.a.santcroos@lumc.nl](mailto:m.a.santcroos@lumc.nl) [m.a.santcroos@lumc.nl](mailto:m.a.santcroos@lumc.nl)
* Guy Allard<br> * Guy Allard<br>
[w.g.Allard@lumc.nl](mailto:w.g.allard@lumc.nl) [w.g.Allard@lumc.nl](mailto:w.g.allard@lumc.nl)
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Program Program
=== ===
| Day | Time | Lesson | Teacher | | Day | Time | Lesson | Teacher |
|-----------------|-------|------------------------------------ |----------| |-------------------|-------|------------------------------------ |----------|
| Monday, 18/9 | 9-10 | Welcome, Introduction to Python (1) | Mihai | | **Monday, 18/9** | 9 - 9:30 | Welcome, Setup | Mihai |
| | 10-11 | Introduction to Python (2) | Jeroen | | | 9:30 - 10:30 | Introduction to Python (1) | Mihai |
| | 11-12 | Introduction to Python (3) | Mihai | | | 10:30 - 11:30 | Introduction to Python (2) | Jeroen |
| | 12-13 | Practical help | | | | 11:30 - 12:30 | Introduction to Python (3) | Mihai |
| Tuesday, 19/9 | 9-10 | Assignments review | | | | 12:30 - 13:00 | Practical help | |
| | 10-11 | More Python Goodness (1) | Mihai | | **Tuesday, 19/9** | 9-10 | Assignments review | |
| | 11-12 | More Python Goodness (2) | Mihai | | | 10-11 | More Python Goodness (1) | Mihai |
| | 12-13 | IPython Notebook | Mark | | | 11-12 | More Python Goodness (2) | Mihai |
| Wednesday, 20/9 | 9-10 | Assignments review | | | | 12-13 | IPython Notebook | Mark |
| | 10-11 | Data manipulation (NumPy, Pandas) | Mark |
| | 11-12 | Data visualisation (1) | Guy | %% Cell type:markdown id: tags:
| | 12-13 | Data visualisation (2) | Guy |
| Thursday, 21/9 | 9-10 | Assignments review | | | Day | Time | Lesson | Teacher |
| | 10-11 | Object-oriented programming | Jonathan | |---------------------|-------|------------------------------------ |----------|
| | 11-12 | Biopython | Guy | | **Wednesday, 20/9** | 9-10 | Assignments review | |
| | 12-13 | Putting everything together | Jeroen | | | 10-11 | Data manipulation (NumPy, Pandas) | Mark |
| | 11-12 | Data visualisation (1) | Guy |
| | 12-13 | Data visualisation (2) | Guy |
| **Thursday, 21/9** | 9-10 | Assignments review | |
| | 10-11 | Object-oriented programming | Jonathan |
| | 11-12 | Biopython | Guy |
| | 12-13 | Putting everything together | Jeroen |
All slides are linked as one-page documents from the course website: [https://git.lumc.nl/courses/programming-course](https://git.lumc.nl/courses/programming-course) All slides are linked as one-page documents from the course website: [https://git.lumc.nl/courses/programming-course](https://git.lumc.nl/courses/programming-course)
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Software requirements Software requirements
=== ===
* Anaconda * Anaconda:
* Python 2.7 * Python 2.7
* NumPy, matplotlib, Biopython * Comes with all that's required:
- Python interpreter, Jupyter Notebook.
- Libraries:
- NumPy, Panda, matplotlib, Bokeh, Biopython, ...
* [Installation instructions](https://docs.anaconda.com/anaconda/install/).
* Git * Git
Anaconda installation instructions [here](https://docs.anaconda.com/anaconda/install/).
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Exercises Assignments
=== ===
You only learn programming by doing it. * We make use of GitHub Classroom.
* GitHub account required.
* Have your laptop open during the lessons. * Receive link with assignment repository.
* Repeat the code from the slides, play around with it. * Own forked repository to work on.
* Do the exercises. - Clone it.
* There will be a few assignments to submit. - Code.
- Push it.
* Direct file upload to repository is also possible.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Getting help Getting help
=== ===
* Ask a teacher. * Ask a teacher.
* If it's private, mail one of the teachers. * If it's private, mail one of the teachers.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from IPython.display import HTML from IPython.display import HTML
def css_styling(): def css_styling():
styles = open('../styles/custom.css', 'r').read() styles = open('../styles/custom.css', 'r').read()
return HTML('<style>' + styles + '</style>') return HTML('<style>' + styles + '</style>')
css_styling() css_styling()
``` ```
%% Output %% Output
<IPython.core.display.HTML object> <IPython.core.display.HTML object>
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
License: [Creative Commons Attribution 3.0 License (CC-by)](http://creativecommons.org/licenses/by/3.0) License: [Creative Commons Attribution 3.0 License (CC-by)](http://creativecommons.org/licenses/by/3.0)
......
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
<span style="font-size: 200%">Introduction to Python (1)</span> <span style="font-size: 200%">Introduction to Python (1)</span>
=== ===
<br>
[Martijn Vermaat](mailto:m.vermaat.hg@lumc.nl), [Department of Human Genetics, Leiden University Medical Center](http://humgen.nl)
[Jeroen Laros](mailto:j.f.j.laros@lumc.nl), [Department of Human Genetics, Leiden University Medical Center](http://humgen.nl)
Based on: [Python Scientific Lecture Notes](http://scipy-lectures.github.io/)
License: [Creative Commons Attribution 3.0 License (CC-by)](http://creativecommons.org/licenses/by/3.0)
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
About Python About Python
=== ===
History History
--- ---
* Created early 90's by Guido van Rossem at CWI. * Created early 90's by Guido van Rossem at CWI.
- Name: Monty Python.
* General purpose, high-level programming language. * General purpose, high-level programming language.
* Design is driven by code readability. * Design is driven by code readability.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
About Python About Python
=== ===
Features Features
--- ---
* Interpreted, no separate compilation step needed. * Interpreted, no separate compilation step needed.
* Imperative and object-oriented programming (and some functional programming). * Imperative and object-oriented programming.
- And some functional programming.
* Dynamic type system. * Dynamic type system.
* Automatic memory management. * Automatic memory management.
We'll come back to most of this. We'll come back to most of this.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
About Python About Python
=== ===
Why Python? Why Python?
--- ---
* Readable and low barrier to entry. * Readable and low barrier to entry.
* Rich scientific libraries. * Rich scientific libraries.
* Many other libraries available. * Many other libraries available.
* Widely used with a large community. * Widely used with a large community.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
About Python About Python
=== ===
Python 2 versus Python 3 Python 2 versus Python 3
--- ---
* Python 3 is backwards incompatible. * Python 3 is backwards incompatible.
* Some libraries don't support it yet. * Some libraries don't support it yet.
* Python 2.7 is the last Python 2. * Python 2.7 is the last Python 2.
* Some Python 3 features are backported in Python 2.7. * Some Python 3 features are backported in Python 2.7.
* Default Python on most distributions is Python 2.7. * Default Python on most distributions is Python 2.7.
We use Python 2.7 for the time being. We use Python 2.7 for the time being.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Running Python code Running Python code
=== ===
Two main ways of writing and executing Python code. Two main ways of writing and executing Python code.
Interactively Interactively
--- ---
* Statement by statement directly in the interpreter. * Statement by statement directly in the interpreter.
Non-interactively Non-interactively
--- ---
* By editing in a file and running the code afterwards. * By editing in a file and running the code afterwards.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
We'll start with the first option. We'll start with the first option.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Running Python code Running Python code
=== ===
The standard Python interpreter The standard Python interpreter
--- ---
Start it by typing `python` on the command line: Start it by typing `python` on the command line:
$ python $ python
Python 2.7.3 (default, Jan 2 2013, 13:56:14) Python 2.7.3 (default, Jan 2 2013, 13:56:14)
[GCC 4.7.2] on linux2 [GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information. Type "help", "copyright", "credits" or "license" for more information.
>>> >>>
* It shows an interpreter prompt. * It shows an interpreter prompt.
* You can give it Python code to interpret. * You can give it Python code to interpret.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Running Python code Running Python code
=== ===
The IPython interpreter The IPython interpreter
--- ---
* Similar to the standard Python interpreter, but with * Similar to the standard Python interpreter, but with
* syntax highlighting, * syntax highlighting,
* tab completion, * tab completion,
* cross-session history, etcetera... * cross-session history, etcetera...
Start it by typing `ipython` on the command line: Start it by typing `ipython` on the command line:
$ ipython $ ipython
Python 2.7.3 (default, Jan 2 2013, 13:56:14) Python 2.7.3 (default, Jan 2 2013, 13:56:14)
Type "copyright", "credits" or "license" for more information. Type "copyright", "credits" or "license" for more information.
IPython 0.13.1 -- An enhanced Interactive Python. IPython 0.13.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features. ? -> Introduction and overview of IPython's features.
%quickref -> Quick reference. %quickref -> Quick reference.
help -> Python's own help system. help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details. object? -> Details about 'object', use 'object??' for extra details.
In [1]: In [1]:
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
From now on, play along in your own IPython interpreter. From now on, play along in your own IPython interpreter.
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Python as a calculator Python as a calculator
=== ===
Integers Integers
--- ---
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
17 17
``` ```
%% Output %% Output
17 17
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
(17 + 4) * 2 (17 + 4) * 2
``` ```
%% Output %% Output
42 42
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Python as a calculator Python as a calculator
=== ===
Floating point numbers Floating point numbers
--- ---
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
3.2 * 18 - 2.1 3.2 * 18 - 2.1
``` ```
%% Output %% Output
55.5 55.5
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
36. / 5 36. / 5
``` ```
%% Output %% Output
7.2 7.2
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Scientific notation: Scientific notation:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
1.3e20 + 2 1.3e20 + 2
``` ```
%% Output %% Output
1.3e+20 1.3e+20
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
1.3 * 10**20 1.3 * 10**20
``` ```
%% Output %% Output
1.3e+20 1.3e+20
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Python as a calculator Python as a calculator
=== ===
The division operator The division operator
--- ---
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
35 / 5 35 / 5
``` ```
%% Output %% Output
7 7
%% Cell type:markdown id: tags:
Division is a bit weird: if you give it integer arguments, the result will also be an integer.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
36 / 5 36 / 5
``` ```
%% Output %% Output
7 7
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Division is a bit weird: if you give it integer arguments, the result will also be an integer.
%% Cell type:markdown id: tags:
Python as a calculator Python as a calculator
=== ===
The division operator The division operator
--- ---
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
35 / 5 35 / 5
``` ```
%% Output %% Output
7 7
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
36 / 5 36 / 5
``` ```
%% Output %% Output
7 7
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Solution 1 Solution 1
--- ---
Give floating point arguments instead of integer arguments. Give floating point arguments instead of integer arguments.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
36. / 5. 36. / 5.
``` ```
%% Output %% Output
7.2 7.2
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Python as a calculator Python as a calculator
=== ===
The division operator The division operator
--- ---
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
35 / 5 35 / 5
``` ```
%% Output %% Output
7 7
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
36 / 5 36 / 5
``` ```
%% Output %% Output
7 7
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Solution 2 Solution 2
--- ---
From Python 3 onwards, division behaves differently. You can actually get that behaviour in Python 2.7: From Python 3 onwards, division behaves differently. You can actually get that behaviour in Python 2.7:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from __future__ import division from __future__ import division
36 / 5 36 / 5
``` ```
%% Output %% Output
7.2 7.2
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Python as a calculator
===
Variables Variables
--- ===
* We can use names to reference values (variables). * We can use names to reference values (variables).
* No need to declare them first or define the type. * No need to declare them first or define the type.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
a = 1.3e20 a = 1.3e20
b = 2
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
a a
``` ```
%% Output %% Output
1.3e+20 1.3e+20
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
b = a + 1.2e19 c = a + 1.5e19 * b
b * 2 c * 2
``` ```
%% Output %% Output
2.84e+20 3.2e+20
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Python's type system (1/2) Python's type system (1/4)
=== ===
Every value has a type, view it using `type`: Every value has a type, view it using `type`:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
type(27) type(27)
``` ```
%% Output %% Output
int int
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
type(3.0 * 2.7) type(3.0 * 2.7)
``` ```
%% Output %% Output
float float
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
type(a) type(a)
``` ```
%% Output %% Output
float float
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Python's type system (2/4)
===
Another example of a builtin datatype is `str`, we'll see more later: Another example of a builtin datatype is `str`, we'll see more later:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
type('I am a homo sapiens') type('I am a homo sapiens')
``` ```
%% Output %% Output
str str
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Python's type system (2/2)
===
Some operations are defined on more than one type, possibly with different meanings. Some operations are defined on more than one type, possibly with different meanings.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
'beer' * 5 + 'whiskey' 'beer' * 5 + 'whiskey'
``` ```
%% Output %% Output
'beerbeerbeerbeerbeerwhiskey' 'beerbeerbeerbeerbeerwhiskey'
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Python's type system (3/4)
===
Dynamic typing means that variables can be assigned values of different types during runtime. Dynamic typing means that variables can be assigned values of different types during runtime.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
a
```
%% Output
1.3e+20
%% Cell type:code id: tags:
``` python
type(a)
```
%% Output
float
%% Cell type:code id: tags:
``` python
a = 'spezi' a = 'spezi'
type(a) type(a)
``` ```
%% Output %% Output
str str
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Python's type system (4/4)
===
Python is strongly typed, meaning that operations on values with incompatible types are forbidden. Python is strongly typed, meaning that operations on values with incompatible types are forbidden.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
'beer' + 34 'beer' + 34
``` ```
%% Output %% Output
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
TypeError Traceback (most recent call last) TypeError Traceback (most recent call last)
<ipython-input-24-ec918fbfdf41> in <module>() <ipython-input-24-ec918fbfdf41> in <module>()
----> 1 'beer' + 34 ----> 1 'beer' + 34
TypeError: cannot concatenate 'str' and 'int' objects TypeError: cannot concatenate 'str' and 'int' objects
%% Cell type:markdown id: tags:
<div class="alert alert-success">
<h1>Hands on!</h1>
<ol>
<li>We’ve seen that b = 2 is legal.
<ul>
<li> What about 2 = b? </li>
<li>How about a = b = 1?</li>
</ul>
</li>
<li>In math notation you can multiply x and y like this: xy.
What happens if you try that in Python?</li>
<li>How many seconds are there in 42 minutes and 42 seconds?</li>
<li>How many miles are there in 16 kilometers? Hint: there are 1.61 kilometers in a mile.</li>
<li>Let's assume that you run a 42 kilometer race in 4 hours 42 minutes and 42 seconds.
<ul>
<li>What is your average pace (time per mile in minutes and seconds)?</li>
<li>What is your average speed in miles per hour?</li>
</ul>
</li>
<li>Use string operations to reference string 'tra la la la' in a variable named <i>song</i>.</li>
<li>If an article costs 249 Euros including the 19% Value Added Tax (VAT), what is the actual VAT amount in Euros for the corresponding article?</li>
</ol>
</div>
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from IPython.display import HTML from IPython.display import HTML
def css_styling(): def css_styling():
styles = open('styles/custom.css', 'r').read() styles = open('../styles/custom.css', 'r').read()
return HTML('<style>' + styles + '</style>') return HTML('<style>' + styles + '</style>')
css_styling() css_styling()
``` ```
%% Output %% Output
<IPython.core.display.HTML at 0x3463a50> <IPython.core.display.HTML object>
%% Cell type:markdown id: tags:
Acknowledgements
========
Martijn Vermaat
[Jeroen Laros](mailto:j.f.j.laros@lumc.nl)
Based on
---------
[Python Scientific Lecture Notes](http://scipy-lectures.github.io/)
License
--------
[Creative Commons Attribution 3.0 License (CC-by)](http://creativecommons.org/licenses/by/3.0)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
,Year,Belgium,Denmark,Netherlands,Sweden
0,1950,17.278599999999997,8.5627,20.2273,14.0332
1,1951,17.3564,8.607399999999998,20.528799999999997,14.140799999999999
2,1952,17.4608,8.6676,20.7642,14.248899999999999
3,1953,17.555500000000002,8.7386,20.986,14.3429
4,1954,17.6388,8.811399999999999,21.2307,14.4272
5,1955,17.7367,8.8784,21.5018,14.5247
6,1956,17.8477,8.9328,21.7792,14.6314
7,1957,17.9787,8.9757,22.0527,14.734300000000001
8,1958,18.1051,9.0302,22.373600000000003,14.8306
9,1959,18.2072,9.0932,22.6954,14.907499999999999
10,1960,18.2376,9.1621,22.973399999999998,14.9607
11,1961,18.331699999999998,9.2338,23.2775,15.0413
12,1962,18.436799999999998,9.2939,23.6113,15.1232
13,1963,18.566200000000002,9.3672,23.931600000000003,15.2087
14,1964,18.7339,9.4404,24.2543,15.3228
15,1965,18.896,9.516200000000001,24.5893,15.4678
16,1966,19.015700000000002,9.595,24.9128,15.6157
17,1967,19.1129,9.6775,25.1965,15.7355
18,1968,19.179699999999997,9.729700000000001,25.4594,15.8246
19,1969,19.2252,9.781500000000001,25.7561,15.936
20,1970,19.275399999999998,9.8576,26.076999999999998,16.085700000000003
21,1971,19.346600000000002,9.901399999999999,26.3891,16.1967
22,1972,19.4222,9.9512,26.6567,16.2449
23,1973,19.4836,10.0152,26.8784,16.2738
24,1974,19.5131,10.0905,27.0903,16.320700000000002
25,1975,19.6017,10.108799999999999,27.3328,16.3854
26,1976,19.6363,10.1451,27.548000000000002,16.4448
27,1977,19.660600000000002,10.1766,27.7125,16.502899999999997
28,1978,19.674599999999998,10.2087,27.8837,16.5517
29,1979,19.6968,10.2336,28.0765,16.587400000000002
30,1980,19.7103,10.245999999999999,28.2994,16.6209
31,1981,19.6976,10.243400000000001,28.4942,16.641
32,1982,19.714599999999997,10.2355,28.625500000000002,16.6503
33,1983,19.716,10.2286,28.7339,16.658
34,1984,19.706,10.2232,28.848399999999998,16.6732
35,1985,19.7165,10.2274,28.9833,16.7008
36,1986,19.729599999999998,10.2408,29.144199999999998,16.7396
37,1987,19.7404,10.254,29.3305,16.795699999999997
38,1988,19.8034,10.2586,29.5202,16.873
39,1989,19.8754,10.2646,29.698,16.9859
40,1990,19.934800000000003,10.2798,29.903,17.1173
41,1991,20.0092,10.3081,30.1391,17.2273
42,1992,20.0903,10.3404,30.3681,17.3364
43,1993,20.1674,10.378499999999999,30.5811,17.4373
44,1994,20.230800000000002,10.4101,30.7657,17.5621
45,1995,20.2735,10.4558,30.9179,17.654
46,1996,20.313285999999998,10.523299999999999,31.061,17.6821
47,1997,20.340452,10.5686,31.2216,17.6925
48,1998,20.406016,10.602599999999999,31.4146,17.702399999999997
49,1999,20.452844,10.63822,31.624,17.716102
50,2000,20.502511,10.674688,31.851039,17.744588
51,2001,20.573149,10.710163999999999,32.092372999999995,17.792254
52,2002,20.665584000000003,10.74851,32.297866,17.849916
53,2003,20.752265,10.774348,32.450617,17.916458
54,2004,20.842273,10.802354000000001,32.563558,17.987062
55,2005,20.957247000000002,10.831956,32.64002,18.059144
56,2006,21.0959255,10.869133999999999,32.692484,18.161009
57,2007,21.251411,10.91483,32.763406,18.296198
58,2008,21.419958,10.978044,32.891203000000004,18.439287
59,2009,21.592997,11.038882000000001,33.060784999999996,18.597040999999997
60,2010,21.67981,11.087638,33.230799000000005,18.756252
61,2011,22.001275999999997,11.133712,33.386160000000004,18.898439
62,2012,22.189700000000002,11.17417,33.509935999999996,19.038762
63,2013,22.356872,11.217568,33.608877,19.200757
64,2014,22.454566,11.279437999999999,33.608877,19.392219
65,2015,,,33.879855,19.392219
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment