Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup (sections 0 to 6) #36

Merged
merged 16 commits into from
Nov 21, 2019
54 changes: 18 additions & 36 deletions tutorials/Python/00_Introduction/Introduction.ipynb
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Python tutorial for absolute beginners"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"###### This tutorial was created by:\n",
"###### Marc Daemgen, Anna Duncan, Nicholas Michelarakis, Fiona Naughton, Naushad Velgy, William Glass and Irfan Alibay\n",
"###### SBCB, Oxford, December 2018"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -29,24 +13,22 @@
"source": [
"Launching python:\n",
"1. Open a terminal window (find the program 'Terminal' on your ubuntu machine and open it).\n",
"2. Type 'python' to open a python session.\n",
"3. Close the session by typing Ctl+D or 'quit()' or 'exit()'\n",
"2. Type `python` to open a python session.\n",
"3. Close the session by typing `Ctl+D` or `quit()` or `exit()`\n",
"\n",
"Launching an ipython notebook:\n",
"1. Open a terminal window\n",
"2. Type 'jupyter notebook'. This will open an interactive ipython notebook in your web browser (like this one).\n",
"3. Close by typing 'Ctl+C' in your terminal window, or via the dropdown menu within the notebook: 'File > Close and halt'."
"3. Close by typing `Ctl+C` in your terminal window, or via the dropdown menu within the notebook: `File > Close and Halt`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Useful resources for python:\n",
"- Documentation home page: https://docs.python.org/3.6/\n",
"- Useful once at this page: Tutorial; Library Reference\n",
"\n",
"- Good python tutorial: https://www.codecademy.com/learn/learn-python"
"- [Python Documentation](https://docs.python.org/3.6/) (tutorials, library reference, ...)\n",
"- [CodeAcademy Python tutorial](https://www.codecademy.com/learn/learn-python)"
]
},
{
Expand All @@ -69,35 +51,35 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The 'print' function takes an input value (some text, in quotation marks) and prints the text as output (without the quotation marks). One should note that Python is case-sensitive - ie. we can't use Print or PRINT.\n",
"The `print` function takes an input value (some text, in quotation marks) and prints the text as output (without the quotation marks). One should note that Python is case-sensitive - ie. we can't use `Print` or `PRINT`.\n",
"\n",
"Note: As of python 3, the inputs to the 'print' function must be placed within parantheses. If you use code developed for python 2.7 or lower, you may notice that this requirement is not followed and therefore will cause issues if run using python 3+. There are other key differences between python 3 and previous versions, some of which will be covered in this tutorial. For a more detailed look into them, the following resource may be of use: https://docs.python.org/3.6/howto/pyporting.html"
"Note: As of python 3, the inputs to the 'print' function must be placed within parantheses. If you use code developed for python 2.7 or lower, you may notice that this requirement is not followed and therefore will cause issues if run using python 3+. There are other key differences between python 3 and previous versions, some of which will be covered in this tutorial. For a more detailed look into them, the following resource may be of use: [Porting Python 2 Code to Python 3](https://docs.python.org/3.6/howto/pyporting.html)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"###### Exercise 0.1:"
"### Exercise 0.1:"
IAlibay marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A first python script:\n",
"1. Open a text editor (eg. gedit) (type 'gedit' into a terminal and press enter; the text editor will open in a new window)\n",
"1. Open a text editor (eg. gedit) (type `gedit` into a terminal and press enter; the text editor will open in a new window)\n",
"2. type the above command into the editor and save the file as 'hello.py' in the home directory\n",
"3. Close gedit\n",
"4. Open a terminal window\n",
"5. Type 'python hello.py' to run the script"
"5. Type `python hello.py` to run the script"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"###### Exercise 0.2:"
"### Exercise 0.2:"
]
},
{
Expand All @@ -120,23 +102,23 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"###### A note on python comments\n",
"### A note on python comments\n",
"\n",
"You will have noticed that the \"# Exercise 0.2\" in the above box does not affect the notebook output. In python in-line code comments are indicated using the # symbol. Any text that comes after this is considered to be a comment and is ignored by the python interpreter. Other means of commenting python code, such as docstrings, also exist, however their use is beyond the scope of this tutorial and will not be covered.\n",
"\n",
"It is considered good practice to comment your code in order to make it more readable for yourself and any future users.\n",
"\n",
"#### Review"
"It is considered good practice to comment your code in order to make it more readable for yourself and any future users."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Review\n",
"\n",
"We have:\n",
"- used a function, print\n",
"- used a function, `print`\n",
"- written our first script\n",
"- run the script using python"
"- run the script using `python`"
]
}
],
Expand All @@ -156,7 +138,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.6.7"
}
},
"nbformat": 4,
Expand Down
74 changes: 37 additions & 37 deletions tutorials/Python/01_BasicTypes/BasicTypes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"metadata": {},
"source": [
"Every object in python has a type.\n",
"For example, the object 'Hello world' is text, also known as a string.\n",
"For example, the object `'Hello world'` is text, also known as a string.\n",
"\n",
"Object types include: \n",
"- strings (ie. text)\n",
Expand Down Expand Up @@ -97,9 +97,9 @@
"source": [
"FAQ:\n",
"\n",
"Do we have to use single quotes to indicate a string? Will double quotes (\"\") work as well?\n",
"Do we have to use single quotes to indicate a string? Will double quotes (`\"\"`) work as well?\n",
"\n",
"Answer: Yes. Single quotes, double quotes, and even triple quotes ('''something''') tell Python that you want a string. When to use one or the other depends on what you are trying to do; check the exercises below for more on this.\n",
"Answer: Yes. Single quotes, double quotes, and even triple quotes (`'''something'''` or `\"\"\"something\"\"\"`) tell Python that you want a string. When to use one or the other depends on what you are trying to do; check the exercises below for more on this.\n",
"\n",
"A word of caution: don't get in the habit of using triple quotes for strings, as these should be reserved for docstrings. As previously mentioned, it is not necessary to know exactly what these are, just know that these are important in other aspect of Python, and it wouldn't be a good idea to mix them with single and double quotation marks."
]
Expand All @@ -108,7 +108,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"###### Exercise 1.1.1: "
"### Exercise 1.1.1: "
IAlibay marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
Expand Down Expand Up @@ -150,7 +150,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also achieve the same effect with single quotes by using a backslash '\\' before the quotation mark you wish to be printed. This 'escapes' the single quote mark from being interpreted as a quotation mark at the end of the string.\n",
"You can also achieve the same effect with single quotes by using a backslash `\\` before the quotation mark you wish to be printed. This \"escapes\" the single quote mark from being interpreted as a quotation mark at the end of the string.\n",
"\n",
"For example:"
]
Expand All @@ -168,7 +168,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"###### Exercise 1.1.2: "
"### Exercise 1.1.2: "
]
},
{
Expand All @@ -195,8 +195,8 @@
"source": [
"More types of quotation marks...\n",
"If you want to include more than one line in your string, you can:\n",
"- use a 'new line character' in your string - this character looks like: '\\n'\n",
"- use triple quotes (''') at either end of your string"
"- use a 'new line character' in your string - this character looks like: `\\n`\n",
"- use triple quotes (`'''` or `\"\"\"`) at either end of your string"
]
},
{
Expand All @@ -222,7 +222,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Review:"
"### Review:"
]
},
{
Expand All @@ -233,8 +233,8 @@
"- strings, surrounded by either 'single quotes' or \"double quotes\"\n",
"- printing strings\n",
"- adding strings together\n",
"- quotes within a string, either using double or single quotes, or using \\'\n",
"- inserting a new line into your string, with a new line character, \\n , or '''triple quotes'''"
"- quotes within a string, either using double or single quotes, or using `\\`\n",
"- inserting a new line into your string, with a new line character, `\\n` , or '''triple quotes'''"
]
},
{
Expand Down Expand Up @@ -293,7 +293,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Multiplying (we use the '*' sign to multiply)"
"Multiplying (we use the `*` sign to multiply)"
]
},
{
Expand All @@ -309,7 +309,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Dividing (use the '/' sign):"
"Dividing (use the `/` sign):"
]
},
{
Expand All @@ -327,7 +327,7 @@
"source": [
"Note that when dividing integers, a floating point type value (i.e. a decimal) will be returned. It is important to note\n",
"that in previous versions of python (v2.7 and lower) only integer types (i.e. whole numbers) would be returned, resulting\n",
"in a rounding down of values. This very specific difference between versions is a frequent source of errors when porting python code. If integer division (i.e. a division that returns only whole numbers) is required, the '//' operation can be used instead.\n",
"in a rounding down of values. This very specific difference between versions is a frequent source of errors when porting python code. If integer division (i.e. a division that returns only whole numbers) is required, the `//` operation can be used instead.\n",
"\n",
"for example:"
]
Expand Down Expand Up @@ -356,7 +356,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Powers, eg. $4^2$ , (using 2 consecutive * symbols):"
"Powers, eg. $4^2$ , (using 2 consecutive `*` symbols):"
]
},
{
Expand All @@ -372,7 +372,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Modular arithmetic (or integer remainders), is done using the % symbol:"
"Modular arithmetic (or integer remainders), is done using the `%` symbol:"
]
},
{
Expand Down Expand Up @@ -409,12 +409,12 @@
"#### Review:\n",
"\n",
"We have covered:\n",
"- addition '+'\n",
"- substraction '-'\n",
"- multiplication '*'\n",
"- division and differences from older versions of python '/' '//'\n",
"- power operations '**'\n",
"- modular arthmetic '%'\n"
"- addition `+`\n",
"- substraction `-`\n",
"- multiplication `*`\n",
"- division and differences from older versions of python (`/` and `//`)\n",
"- power operations `**`\n",
"- modular arthmetic `%`\n"
]
},
{
Expand Down Expand Up @@ -489,7 +489,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"###### Exercise 1.3.1"
"### Exercise 1.3.1"
]
},
{
Expand All @@ -498,10 +498,10 @@
"source": [
"Find:\n",
" \n",
"a) 8.3 + 4\n",
"b) 5.1 x 2.5\n",
"c) 10 / 3 (the answer should be a floating point value)\n",
"d) $8.1^3$ "
"- 8.3 + 4\n",
"- 5.1 x 2.5\n",
"- 10 / 3 (the answer should be a floating point value)\n",
"- $8.1^3$ "
]
},
{
Expand Down Expand Up @@ -551,7 +551,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Floating point arithmetic is not exact, because computers work in base 2, which means that numbers like 1/10 are not stored exactly.\n",
"Floating point arithmetic is not exact, because computers work in base 2, which means that numbers like `1/10` are not stored exactly.\n",
"\n",
"Usually this is not a problem - floating point values are correct to ~17 significant figures on modern computers - however, it can mean that small errors creep in:"
]
Expand All @@ -569,7 +569,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"###### Exercise 1.3.2"
"### Exercise 1.3.2"
]
},
{
Expand All @@ -594,15 +594,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Review"
"### Review"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Numbers in python are integers or floating points (specified by using a decimal point, '.', in the number)\n",
"- Floating point values are specified by using a decimal point (.) in the number\n",
"- Numbers in python are integers or floating points (specified by using a decimal point, `.`, in the number)\n",
"- Floating point values are specified by using a decimal point (`.`) in the number\n",
"- Can also perform addition, subtraction, multiplication, division and powers with floating points\n",
"- Precision can be an issue with floating point values"
]
Expand All @@ -619,9 +619,9 @@
"metadata": {},
"source": [
"We can also group strings, integers and floating point values into new objects:\n",
"- list, surrounded by square brackets, [ ], succesive entries are separated by ','. These are used a lot.\n",
"- tuple, surrounded by round brackets, ( ), succesive entries are separated by ','. Like a list except that, once specified, its elements can't be changed.\n",
"- dictionary, surrounded by curly brackets, { }, succesive entries are separated by ','. These are lists of pairs."
"- list, surrounded by square brackets, `[ ]`, succesive entries are separated by `,`. These are used a lot.\n",
IAlibay marked this conversation as resolved.
Show resolved Hide resolved
"- tuple, surrounded by round brackets, `( )`, succesive entries are separated by `,`. Like a list except that, once specified, its elements can't be changed.\n",
"- dictionary, surrounded by curly brackets, `{ }`, succesive entries are separated by `,`. These are lists of pairs, where each element in a pair is separated by `:`."
]
},
{
Expand Down Expand Up @@ -694,7 +694,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We can check what type of object we are dealing with using the 'type()' function.\n",
"We can check what type of object we are dealing with using the `type()` function.\n",
"\n",
"For example:\n"
]
Expand Down Expand Up @@ -752,7 +752,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.6.7"
}
},
"nbformat": 4,
Expand Down
Loading