diff --git a/_extensions/mcanouil/iconify/LICENSE b/_extensions/mcanouil/iconify/LICENSE index 8965781..4948d9e 100644 --- a/_extensions/mcanouil/iconify/LICENSE +++ b/_extensions/mcanouil/iconify/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Mickaël Canouil +Copyright (c) 2024 Mickaël Canouil Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/python_intro/modules/datatypes/exercises.qmd b/python_intro/modules/datatypes/exercises.qmd index b0347cf..cdb6e19 100644 --- a/python_intro/modules/datatypes/exercises.qmd +++ b/python_intro/modules/datatypes/exercises.qmd @@ -1,5 +1,3 @@ # Exercise Complete the following exercise by clicking [here](https://opensourcecourse.github.io/hub/lab/?path=data_types.ipynb) - - diff --git a/python_intro/modules/datatypes/img.png b/python_intro/modules/datatypes/img.png deleted file mode 100644 index 75cf198..0000000 Binary files a/python_intro/modules/datatypes/img.png and /dev/null differ diff --git a/python_intro/modules/datatypes/overview.qmd b/python_intro/modules/datatypes/overview.qmd index c912556..b28e5ad 100644 --- a/python_intro/modules/datatypes/overview.qmd +++ b/python_intro/modules/datatypes/overview.qmd @@ -13,16 +13,21 @@ a very good place to start This module covers some common built-in datatypes in python. -Understanding these datatypes is not only important for using python effectively, but also for understanding more advanced features of python's type system and implementation. +Understanding these datatypes is not only important for using python effectively, but also for understanding more advanced concepts of python's type system. # Objectives -In this module we will learn about: +After completing this module you will be able to: -1. Numeric types: int, float, complex -2. Boolean -3. Strings -4. Containers: list and dict +1. Create python variables + +2. Identify usages of basic python types, including: + * Numeric types: int, float, complex + * Boolean + * Strings + * Container types: list and dict + +3. Debug short code snippets using these concepts # Reading diff --git a/python_intro/modules/datatypes/slides.qmd b/python_intro/modules/datatypes/slides.qmd index aba7c3b..b92b3f5 100644 --- a/python_intro/modules/datatypes/slides.qmd +++ b/python_intro/modules/datatypes/slides.qmd @@ -24,7 +24,7 @@ Variables reference a value
:::{.fragment} -```{.python filename="functions" code-line-numbers="1|2|3|4|5"} +```{.python filename="variables" code-line-numbers="1|2|3|4|5"} bar = 1 foo = "two" que = 3.0 @@ -56,8 +56,8 @@ Why doesn't this work? :::{.fragment} ```{.python filename="variables"} -int_2 = int_1 -int_1 = 2 +var_1 = var_2 +var_2 = 2 ``` ::: @@ -94,6 +94,8 @@ print(foo) - Python supports `ints`, `floats`, `complex` - Operators return appropriate types +
+ ```{.python filename="numbers" code-line-numbers="1|2|3|4|5"} my_sum = 42 + 2.7182818 # 44.7182818 my_product = 42 * 2 # 84 @@ -106,6 +108,8 @@ my_expontential = 10**6 # 1_000_000 How do you think complex numbers behave when added by an `int`? +
+ :::{.fragment} ```{.python filename="numbers"} my_complex = complex(1, 1) @@ -117,18 +121,32 @@ my_complex + 1 # Boolean - Booleans can be either `True` or `False` -- Everything in python is "truthy" except: - - 0, empty things, `None` :::{.fragment} -```{.python filename="variables" code-line-numbers="1-2|4-5|7"} +```{.python filename="boolean" code-line-numbers="1-2|4-5"} so_true = True so_false = False my_var1 = so_true and so_false my_var2 = so_true or so_false +``` +::: + + -another_bool = bool(0) +# Boolean + +- Everything in python is "truthy" except: + - 0, empty things, `None`, `False`, ... + +
+ +:::{.fragment} +```{.python filename="boolean" code-line-numbers="1|2|3|4"} +bool(10) +bool(1.0) +bool("") +bool(0) ``` ::: @@ -138,7 +156,7 @@ another_bool = bool(0) Strings represent characters :::{.fragment} -```{.python filename="variables" code-line-numbers="1|3|5"} +```{.python filename="strings" code-line-numbers="1|3|5|7-9"} my_str = "Bloom's Taxonomy" str_concat = my_str + " is great!" @@ -153,10 +171,12 @@ upper_case = my_str.upper() # Strings: Knowledge Check -What do these functions do? +What do these methods do? + +
:::{.fragment} -```{.python code-line-numbers="1|3|4"} +```{.python filename="strings" code-line-numbers="1|3|4"} my_str = "a farewell to arms" print(my_str.title()) @@ -171,7 +191,7 @@ print(my_str.startswith("a")) :::{.fragment} -```{.python filename="variables" code-line-numbers="1|3|4|5|6|7-8|9-10"} +```{.python filename="lists" code-line-numbers="1|3|4|5|6|7-8|9-10"} my_list = [1, 2, True, 0.0] len(my_list) # get the length of the list @@ -181,115 +201,40 @@ my_list[1:2] # gets middle values # append value to end my_list.append("Grapes of Wrath") # join two lists together -concated = [1,2,3] + [4, 5, 6] +concated = [1, 2, 3] + [4, 5, 6] ``` ::: -# Lists: Knowledge Check - -:::{.fragment} -```{.python filename="lists" code-line-numbers="1|3|4|5|6"} -my_list = [1, 2, 3] - -len(my_list) -my_list[1] -my_list.append(8) -my_list[-2] -``` -::: - - -# Dictionaries - -:::: {.columns} - -::: {.column width="50%"} - -::: {.incremental} -
+# Lists -- A Key -> Value container -- Keys must be **unique** and **hashable** -- Values have no restrictions -::: +- Lists support iteration. -::: -::: {.column width="50%"} :::{.fragment} -```{mermaid} -%%| fig-width: 4.2 -flowchart LR - A[Key 1] --> B(Value 1) - C[Key 2] --> D(Value 2) - E[Key 3] --> D -``` -::: - -::: - -::: - - -# Dictionaries - -- Accessing keys - -```{.python code-line-numbers="1-5|7|8|9"} -map = { - 1: 2, - 4: 3.1415, - "time": "money", -} - -map[1] # 2 -map[4] # 3.1425 -time = map["time"] # money -``` - -# Dictionaries - -- Adding/removing keys - -```{.python code-line-numbers="1-3|5|6"} -map = { - 1: 2, -} +```{.python filename="lists" code-line-numbers="1|3-4"} +some_phrase = ["Heghlu'meH", "QaQ", "jajvam"] -map['time'] = "money" -map.pop(1) -``` - - -# Dictionaries: Knowledge Check - -
- -```{.python code-line-numbers="1-4|6|7|8"} -map = { - 1: 2, - "bob": "sue", -} - -map[1] -map["bob"] -map["sue"] +for word in some_phrase: + print(word) ``` +::: -# Dictionaries: Intuition Check +# Lists: Knowledge Check
-```{.python} -map = { - 1: 2, - "bob": "sue", -} +:::{.fragment} +```{.python filename="lists" code-line-numbers="1|3|4|5|6"} +my_list = [1, 2, 3] -len(map) +len(my_list) +my_list[1] +my_list.append(8) +my_list[-2] ``` +::: # Exercise