Skip to content

Commit 760bd8c

Browse files
add built-in labs; review funcs
1 parent 1b6353d commit 760bd8c

9 files changed

Lines changed: 357 additions & 30 deletions

book/02_types_data_structures.ipynb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,20 @@
20312031
"d[1,2,3] # optionally without parenthesis"
20322032
]
20332033
},
2034+
{
2035+
"cell_type": "markdown",
2036+
"id": "122a32d9-0707-4f3f-a71c-47ba7d30f5d5",
2037+
"metadata": {},
2038+
"source": [
2039+
"All these built-in types that we've seen so far can take you already pretty far in manipulating data, both for quick exploration and for more detailed analysis.\n",
2040+
"So it will really pay off to have a good grasp on them, take your time to learn them!\n",
2041+
"\n",
2042+
"Here's a talk for you to watch later that hammers home this point with great mastery:\n",
2043+
"\n",
2044+
"\n",
2045+
"{{< video https://www.youtube.com/watch?v=lyDLAutA88s&t=1850s >}}"
2046+
]
2047+
},
20342048
{
20352049
"cell_type": "markdown",
20362050
"id": "c1d38ca9-5a02-4b4a-b793-82da9aa3ed29",
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
"id": "493c0563-f1b4-4438-af55-0915a3c6a48d",
1818
"metadata": {},
1919
"source": [
20-
"Let's take a look at a few syntax aspects that allow us to control how our program flows.\n",
21-
"\n",
22-
"We can loop over *things* (we'll get back to this later):"
20+
"Let's take a look at a few syntax aspects that allow us to control how our program flows."
2321
]
2422
},
2523
{
@@ -132,7 +130,7 @@
132130
"id": "bc862721-3251-44c2-87b9-79fb6d4b4770",
133131
"metadata": {},
134132
"source": [
135-
"If you really need the indices to carry some other operation, you can get them as you go with `enumerate`, which returns a tuple:"
133+
"If you really need the indices to carry out some other operation, you can get them as you go with `enumerate`, which returns a tuple:"
136134
]
137135
},
138136
{
@@ -190,7 +188,7 @@
190188
"id": "9dd95ac6-450a-4eb5-b6a1-b68ef8150691",
191189
"metadata": {},
192190
"source": [
193-
"Importantly, Python doesn't care about `what` data type we are looping over – all that matters is the data \"knows\" how to be looped over:"
191+
"Importantly, Python doesn't care about _what_ data type we are looping over – all that matters is the data \"knows\" how to be looped over:"
194192
]
195193
},
196194
{
@@ -291,9 +289,9 @@
291289
"id": "0a4ee03e-973a-42c9-a22d-515ba2f1dca2",
292290
"metadata": {},
293291
"source": [
294-
"We say something is \"falsy\" when it evaluates to `False`, despite it not being the boolen value `False`.\n",
292+
"We say something is \"falsy\" when it evaluates to `False`, despite it not being the literal boolean value `False`.\n",
295293
"\n",
296-
"Empty containers (lists, tuples, dicts, sets) are \"falsy\", which can be handy:"
294+
"For example, the number 0, empty strings, empty collections (lists, tuples, dicts, sets) are \"falsy\", which can be handy:"
297295
]
298296
},
299297
{
@@ -436,7 +434,7 @@
436434
"name": "python",
437435
"nbconvert_exporter": "python",
438436
"pygments_lexer": "ipython3",
439-
"version": "3.10.13"
437+
"version": "3.13.3"
440438
}
441439
},
442440
"nbformat": 4,
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
"metadata": {},
1818
"source": [
1919
"## Exceptions\n",
20-
"When our program runs into an error, Python throws an Exception.\n",
20+
"When our program runs into an error, the execution stops and Python throws a so-called _Exception_. \n",
2121
"There several different types of exceptions and they work as a way to communicate what went wrong.\n",
22-
"Sometimes we simply want to let the program crash because the problem is completely unexpected or because we do not have a good solution to deal with it at run time.\n",
22+
"Sometimes we simply want to let the program crash because the problem is completely unexpected or because we do not have a good solution to deal with it, for example we divide by 0. \n",
23+
"But some other times we want to handle it differently, for example if we are getting data from a website that is transiently unavailable we might want to retry after a few seconds.\n",
2324
"\n",
2425
"One of the language constructs to deal with errors in Python is `try-except`, which has this structure:\n",
2526
"```python\n",
@@ -274,7 +275,7 @@
274275
"name": "python",
275276
"nbconvert_exporter": "python",
276277
"pygments_lexer": "ipython3",
277-
"version": "3.10.13"
278+
"version": "3.13.3"
278279
}
279280
},
280281
"nbformat": 4,

book/04_functions.ipynb

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"outputs": [],
3838
"source": [
3939
"def identity(a, b): # only positional arguments\n",
40-
" return a, b"
40+
" return a, b # we can return more than one thing"
4141
]
4242
},
4343
{
@@ -99,7 +99,7 @@
9999
"metadata": {},
100100
"source": [
101101
"::: {.callout-important }\n",
102-
"Python functions **always** return a value, even without a `return` statement, in which case the return value will be `None`.\n",
102+
"Python functions **always** return a value, **even without** a `return` statement, in which case the return value will be `None`.\n",
103103
":::"
104104
]
105105
},
@@ -150,7 +150,7 @@
150150
"id": "10383a76-442f-4ece-9a44-cbfcae681403",
151151
"metadata": {},
152152
"source": [
153-
"This three definitions are equivalent:"
153+
"These three definitions are equivalent:"
154154
]
155155
},
156156
{
@@ -169,8 +169,7 @@
169169
" return\n",
170170
" \n",
171171
"def f():\n",
172-
" print(\"hello\")\n",
173-
" # The return statement is implicitly here "
172+
" print(\"hello\")"
174173
]
175174
},
176175
{
@@ -186,7 +185,7 @@
186185
"id": "cd15c9c6-2067-48ca-b35b-a715d2a762ad",
187186
"metadata": {},
188187
"source": [
189-
"We can write a function with arbitrary arguments.\n",
188+
"We can write a function with an arbitrary (undefined) number of arguments.\n",
190189
"For that, we use the syntax `*args`.\n",
191190
"The `args` will be put into a tuple:"
192191
]
@@ -347,14 +346,24 @@
347346
"general(1, 2, first=\"hello\", second=\"world\")"
348347
]
349348
},
349+
{
350+
"cell_type": "markdown",
351+
"id": "4f6cdcf8-c9f6-46e7-9cba-cfa35e2a67a9",
352+
"metadata": {},
353+
"source": [
354+
"::: {.callout-tip}\n",
355+
"Use key-word (named) arguments by default, it will make your code much more readable, maintainable and easier to debug.\n",
356+
":::"
357+
]
358+
},
350359
{
351360
"cell_type": "markdown",
352361
"id": "38e5d4a8-0df5-4c34-9dab-67f93dab46af",
353362
"metadata": {},
354363
"source": [
355364
"## Functions are values\n",
356365
"\n",
357-
"We can assign functions to variables and pass them around, like any other object (people call this to have \"functions as first-class citizen\")."
366+
"We can assign functions to variables and pass them around, like any other object (people call this to have \"_functions as first-class citizen_\" in the language)."
358367
]
359368
},
360369
{
@@ -647,7 +656,7 @@
647656
"def early():\n",
648657
" if 1 > 0:\n",
649658
" return \"first condition\"\n",
650-
" if 2 > 0: # This code will never be evaluated\n",
659+
" if 2 > 0: # This code will never be reached \n",
651660
" return \"second condition\""
652661
]
653662
},
@@ -887,7 +896,7 @@
887896
"source": [
888897
"## Exercises\n",
889898
"1) Write a function called `intro` that takes two positional arguments, name and age, and prints a sentence introducing a person. The function should return nothing.\n",
890-
"2) Repeat it, but adding an optional argument, city. The function should now return the introducing string (consider handling the city)\n",
899+
"2) Repeat it, but adding an optional argument, city. The function should now return the introducing string and handle the city input too.\n",
891900
"3) Write a function called `sort_dict_by_value` that takes a dictionary and returns a dictionary sorted by value.\n",
892901
"4) Write a function that takes an arbitrary number of key-word __only__ arguments representing pairs (name, age) and returns a list of tuples sorted by age.\n",
893902
"For example:\n",
@@ -937,7 +946,7 @@
937946
"name": "python",
938947
"nbconvert_exporter": "python",
939948
"pygments_lexer": "ipython3",
940-
"version": "3.10.13"
949+
"version": "3.13.3"
941950
}
942951
},
943952
"nbformat": 4,

book/05_comprehensions.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"id": "493c0563-f1b4-4438-af55-0915a3c6a48d",
1818
"metadata": {},
1919
"source": [
20-
"A commonly used language construct are comprehensions.\n",
21-
"They can have performance advantages and can improve readability if properly used."
20+
"A commonly used language construct are comprehensions. \n",
21+
"They can have performance advantages and improve readability if properly used."
2222
]
2323
},
2424
{

book/081_pandas.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"name": "python",
8888
"nbconvert_exporter": "python",
8989
"pygments_lexer": "ipython3",
90-
"version": "3.10.13"
90+
"version": "3.13.3"
9191
}
9292
},
9393
"nbformat": 4,

book/_quarto.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
project:
22
type: book
3-
# output-dir: ../docs
43

54
book:
65
title: "Python Course"
@@ -36,16 +35,17 @@ book:
3635
- 01_1_getting_started.ipynb
3736
- 01_2_executing_code.ipynb
3837
- 02_types_data_structures.ipynb
39-
- 03_flow_control.ipynb
40-
- 031_error_handling.ipynb
38+
- 03_1_flow_control.ipynb
39+
- 03_2_error_handling.ipynb
4140
- 04_functions.ipynb
4241
- 041_scope.ipynb
4342
- 05_comprehensions.ipynb
44-
- 051_oop.ipynb
43+
- lab_syntax.ipynb
4544
- 06_imports.ipynb
4645
- 061_dependencies.ipynb
4746
- 062_read_and_write.ipynb
4847
- 063_common_data_formats.ipynb
48+
- 051_oop.ipynb
4949
- 08_numpy.ipynb
5050
- 081_pandas.ipynb
5151
- 09_plotting.ipynb
@@ -58,7 +58,7 @@ book:
5858
- 999_glossary.ipynb
5959
- references.qmd
6060

61-
bibliography: references.bib
61+
# bibliography: references.bib
6262

6363
format:
6464
html:

book/lab_explore_data_solutions.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@
16901690
"name": "python",
16911691
"nbconvert_exporter": "python",
16921692
"pygments_lexer": "ipython3",
1693-
"version": "3.10.13"
1693+
"version": "3.13.3"
16941694
}
16951695
},
16961696
"nbformat": 4,

0 commit comments

Comments
 (0)