Skip to content

Commit

Permalink
refactor: minor changes to notebook 02
Browse files Browse the repository at this point in the history
  • Loading branch information
robinengler committed May 3, 2022
1 parent 2fb7fce commit 32b7cbb
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions notebooks/02_python_structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@
"\n",
"[Back to ToC](#toc)\n",
"\n",
"## Conditional statements : `if` , `elif`, `else` <a id='2'></a>\n",
"## Conditional statements: `if` , `elif`, `else` <a id='2'></a>\n",
"------------------------------------------------------\n",
"\n",
"There are several ways to control the flow of your code using logical statements.\n",
"* The **`if`** keyword followed by an expression defines a block that will be executed only if the \n",
" given statement is `True`.\n",
" given expression evaluates to `True`.\n",
"* The **`else`** keyword defines a block to be executed if the previous `if` or `elif` expressions\n",
" evaluated to `False`.\n",
"* Tests for additional conditions can be added using the **`elif`** keyword (contraction of `else if`).\n"
Expand All @@ -187,6 +187,13 @@
"![image.png](img/if_else_figure_2.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Single **`if`**:"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -202,6 +209,13 @@
"print(\"This is a\", toppings, \"sandwich\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* **`if... else...`** statement: "
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -256,11 +270,11 @@
" `==`,`>`,`<`,`>=`,`<=`,`!=`.\n",
"\n",
"Conditions may be further combined using **logical operators** :\n",
"* `and` : combines 2 statements and returns `True` if both are `True`\n",
"* `or` : combines 2 statements and returns `True` if at least one is `True`\n",
"* `in` : returns `True` if the element to its left is found inside the container to its right\n",
"* `not` : inverts a `True` to `False` and vice-versa\n",
"* `is` : returns `True` if two variable reference the same object **(but we have not talked about this yet...)**\n"
"* **`and`**: combines 2 statements and returns `True` if both are `True`.\n",
"* **`or`** : combines 2 statements and returns `True` if at least one is `True`.\n",
"* **`in`** : returns `True` if the element to its left is found inside the container to its right (**`not in`** can be used to check the reverse).\n",
"* **`not`** : inverts a `True` to `False` and vice-versa.\n",
"* **`is`** : returns `True` if two variable reference the same object - but we have not talked about this yet... (**`is not`** can be used to check the reverse).\n"
]
},
{
Expand Down Expand Up @@ -341,7 +355,7 @@
"\n",
"In the first lesson we have already used a few of python's built-in functions: `help()`,`print()`,`len()`, ... , as well as some objects methods, which are functions as well.\n",
"\n",
"While it is recomended to use python's built-in functions when available (they will almost always be much faster than your own code), they obviously do not cover all the possible functionalities we might need. It it is thus really useful to be able to write our own functions!\n",
"While it is recomended to use python's built-in functions when available (they will almost always be much faster than your own code), they obviously do not cover all the possible functionalities we might need. This is why it is really useful to be able to write our own functions!\n",
"\n",
"In python, **functions are declared using the `def` keyword**, followed by the named of the function, brakets `()` where arguments can be specified, and finally a column `:` character.\n",
"\n",
Expand Down Expand Up @@ -380,9 +394,9 @@
"\n",
"### Function arguments <a id='5'></a>\n",
"\n",
"The above function has not arguments - no variable is defined between the `()` in its declaration. While not a problem *per se*, it limits the usefulness and flexibility of the function, since it will always do the exact same thing each time we call it.\n",
"Our above `greetings()` function has no arguments - no variable is defined between the `()` in its declaration. While not a problem *per se*, it limits the usefulness and flexibility of the function, since it will always do the exact same thing each time we call it.\n",
"\n",
"Here is a variation of this function, with a `name` **argument** added. An **argument** is a value that is passed to a function and that can make its behavior change."
"Here is a variation of this function, with a `name` **argument** added. An **argument** is a value that is passed to a function, can be used in the function as a variable, and that can make its behavior change."
]
},
{
Expand Down

0 comments on commit 32b7cbb

Please sign in to comment.