From 977b8af130f3296ec6d0ce18714d09be6d1d3ceb Mon Sep 17 00:00:00 2001 From: David Herbert <49239555+davidherbert2@users.noreply.github.com> Date: Mon, 5 Oct 2020 13:08:05 +0100 Subject: [PATCH 1/7] adding clarification aboutr references (#370) --- episodes/03-types-conversion.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/episodes/03-types-conversion.md b/episodes/03-types-conversion.md index f20125577..3785cb6b9 100644 --- a/episodes/03-types-conversion.md +++ b/episodes/03-types-conversion.md @@ -180,6 +180,23 @@ three squared is 9.0 the former updates automatically. - This does **not** happen in programming languages. +Most of the time, variable assignment creates a new storage location for the value, so in this simple example: + +```python +a = 1 +b = a +a = 2 +print('a is', a, 'and b is', b) +``` + +```output +a is 2 and b is 1 +``` + +`b` is a **copy** of `a`, a separate storage location, so subsequent assignment of a new value to `a` leaves `b` completely unaffected. + +Here is a slightly more complicated example involving computation on the second value: + ```python variable_one = 1 variable_two = 5 * variable_one @@ -196,6 +213,8 @@ first is 2 and second is 5 - Afterwards, the value of `variable_two` is set to the new value and *not dependent on `variable_one`* so its value does not automatically change when `variable_one` changes. +Sometimes, however (and this can happen with Python list types, described in more detail in Episode 11:Lists), variables can point to the same storage location. Think of a cell in a spreadsheet which depends on another cell. Updating the latter will automatically update the former. The dependent cell is actually a **reference** to the original, not a distinct copy of it. + ::::::::::::::::::::::::::::::::::::::: challenge ## Fractions From b681598dd8827418b508ad77695df6b2c2bee948 Mon Sep 17 00:00:00 2001 From: David Herbert <49239555+davidherbert2@users.noreply.github.com> Date: Mon, 5 Oct 2020 13:10:00 +0100 Subject: [PATCH 2/7] Slightly better wording --- episodes/03-types-conversion.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/episodes/03-types-conversion.md b/episodes/03-types-conversion.md index 3785cb6b9..8a25b8495 100644 --- a/episodes/03-types-conversion.md +++ b/episodes/03-types-conversion.md @@ -213,7 +213,7 @@ first is 2 and second is 5 - Afterwards, the value of `variable_two` is set to the new value and *not dependent on `variable_one`* so its value does not automatically change when `variable_one` changes. -Sometimes, however (and this can happen with Python list types, described in more detail in Episode 11:Lists), variables can point to the same storage location. Think of a cell in a spreadsheet which depends on another cell. Updating the latter will automatically update the former. The dependent cell is actually a **reference** to the original, not a distinct copy of it. +Sometimes, however (and this can happen with Python list types, described in more detail in Episode 11:Lists), more than one variable can point to the same storage location. Think of a cell in a spreadsheet which depends on another cell. Updating the latter will automatically update the former. The dependent cell is actually a **reference** to the original, not a distinct copy of it. ::::::::::::::::::::::::::::::::::::::: challenge From 3ab4d933b26cb78e3cf537a000008ee8b45fe3f0 Mon Sep 17 00:00:00 2001 From: David Herbert <49239555+davidherbert2@users.noreply.github.com> Date: Mon, 5 Oct 2020 15:18:20 +0100 Subject: [PATCH 3/7] Wording of references/relevance to lists (#370) --- episodes/03-types-conversion.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/episodes/03-types-conversion.md b/episodes/03-types-conversion.md index 8a25b8495..145b12a26 100644 --- a/episodes/03-types-conversion.md +++ b/episodes/03-types-conversion.md @@ -213,7 +213,7 @@ first is 2 and second is 5 - Afterwards, the value of `variable_two` is set to the new value and *not dependent on `variable_one`* so its value does not automatically change when `variable_one` changes. -Sometimes, however (and this can happen with Python list types, described in more detail in Episode 11:Lists), more than one variable can point to the same storage location. Think of a cell in a spreadsheet which depends on another cell. Updating the latter will automatically update the former. The dependent cell is actually a **reference** to the original, not a distinct copy of it. +Sometimes, however (e.g. with Python list types, described in more detail in Episode 11:Lists - under section 'Copying (or Not)'), more than one variable *can* point to the same storage location. Think of a cell in a spreadsheet which depends on another cell. Updating the latter will automatically update the former. The dependent cell is actually a **reference** to the original, not a distinct copy of it. ::::::::::::::::::::::::::::::::::::::: challenge From 93d77be9cf766b51aed31d29db36e818daa6b857 Mon Sep 17 00:00:00 2001 From: Brock Date: Thu, 7 Aug 2025 14:06:42 +0200 Subject: [PATCH 4/7] Clarify explanation of mutable references (#370) --- episodes/03-types-conversion.md | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/episodes/03-types-conversion.md b/episodes/03-types-conversion.md index 145b12a26..64cc863e1 100644 --- a/episodes/03-types-conversion.md +++ b/episodes/03-types-conversion.md @@ -173,14 +173,21 @@ half is 0.5 three squared is 9.0 ``` -## Variables only change value when something is assigned to them. - -- If we make one cell in a spreadsheet depend on another, - and update the latter, - the former updates automatically. -- This does **not** happen in programming languages. - -Most of the time, variable assignment creates a new storage location for the value, so in this simple example: +## Assignment changes the value of a variable, it does not create links between variables. + +- In the spreadsheet context, + - If we use a formula to connect one cell to another, + and update the latter, + the former updates automatically. + - In contrast, if we copy one cell and paste its contents into another cell, + the second cell will not update if the first cell changes. + To update the second cell, we would need to copy and paste again. +- Assignment (`=` operator) in python works like copy and paste in spreadsheets + not like a spreadsheet formula connecting the two cells. + In other words, after a variable is used to assign a value to another variable, + reassigning the first variable does not change the second variable. + +To demostrate this: ```python a = 1 @@ -193,7 +200,7 @@ print('a is', a, 'and b is', b) a is 2 and b is 1 ``` -`b` is a **copy** of `a`, a separate storage location, so subsequent assignment of a new value to `a` leaves `b` completely unaffected. +When `b = a` is run, `a`'s value (`1`) is assigned to `b`, but no ongoing link is created between `a` and `b`. Here is a slightly more complicated example involving computation on the second value: @@ -213,7 +220,7 @@ first is 2 and second is 5 - Afterwards, the value of `variable_two` is set to the new value and *not dependent on `variable_one`* so its value does not automatically change when `variable_one` changes. -Sometimes, however (e.g. with Python list types, described in more detail in Episode 11:Lists - under section 'Copying (or Not)'), more than one variable *can* point to the same storage location. Think of a cell in a spreadsheet which depends on another cell. Updating the latter will automatically update the former. The dependent cell is actually a **reference** to the original, not a distinct copy of it. +Some data types that we haven't encountered yet (e.g. lists) have links inside them so they behave differently than described above. An example of this is shown in [Episode 11: Lists](../11-lists.md#copying-or-not). Assigning one of these values to a new variable is a bit like copying and pasting a formula from one cell to another. If the cells referenced in the formula change, then both cells that contain the formula will also change. However, unlike in a spreadsheet, these variables ("formula cells") can be used to change the referenced data (analogous to cells referenced by the formula). ::::::::::::::::::::::::::::::::::::::: challenge From f2229e662044184e42f8029fb29d528a3ad84d79 Mon Sep 17 00:00:00 2001 From: Allen Lee Date: Thu, 30 Oct 2025 18:24:58 -0700 Subject: [PATCH 5/7] fix: minor text refinement --- episodes/03-types-conversion.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/episodes/03-types-conversion.md b/episodes/03-types-conversion.md index 64cc863e1..9de7c22ae 100644 --- a/episodes/03-types-conversion.md +++ b/episodes/03-types-conversion.md @@ -182,12 +182,12 @@ three squared is 9.0 - In contrast, if we copy one cell and paste its contents into another cell, the second cell will not update if the first cell changes. To update the second cell, we would need to copy and paste again. -- Assignment (`=` operator) in python works like copy and paste in spreadsheets +- Assignment (the `=` operator) in python works like copy and paste in spreadsheets not like a spreadsheet formula connecting the two cells. In other words, after a variable is used to assign a value to another variable, reassigning the first variable does not change the second variable. -To demostrate this: +To demonstrate this: ```python a = 1 @@ -208,19 +208,19 @@ Here is a slightly more complicated example involving computation on the second variable_one = 1 variable_two = 5 * variable_one variable_one = 2 -print('first is', variable_one, 'and second is', variable_two) +print('variable_one is', variable_one, 'and variable_two is', variable_two) ``` ```output -first is 2 and second is 5 +variable_one is 2 and variable_two is 5 ``` -- The computer reads the value of `variable_one` when doing the multiplication, +- Python reads the value of `variable_one` when doing the multiplication, creates a new value, and assigns it to `variable_two`. -- Afterwards, the value of `variable_two` is set to the new value and *not dependent on `variable_one`* so its value +- Afterwards, `variable_two` is set to this new value and *is not dependent on `variable_one`* so its value does not automatically change when `variable_one` changes. -Some data types that we haven't encountered yet (e.g. lists) have links inside them so they behave differently than described above. An example of this is shown in [Episode 11: Lists](../11-lists.md#copying-or-not). Assigning one of these values to a new variable is a bit like copying and pasting a formula from one cell to another. If the cells referenced in the formula change, then both cells that contain the formula will also change. However, unlike in a spreadsheet, these variables ("formula cells") can be used to change the referenced data (analogous to cells referenced by the formula). +Some data types that we haven't encountered yet (e.g. _lists_, _dictionaries_, and _objects_) have "links" inside them so they behave somewhat differently when you assign values to their *contents*. An example of this is shown in [Episode 12: Lists](../11-lists.md#copying-or-not). Assigning a list value to a new variable is like copying and pasting a formula from one cell to another. When you update an item in that list with the new value, you're updating that canonical list. ::::::::::::::::::::::::::::::::::::::: challenge From 3aa1532819c90f47387587fde000952535756632 Mon Sep 17 00:00:00 2001 From: Brock Date: Fri, 31 Oct 2025 16:44:02 +0100 Subject: [PATCH 6/7] Update episodes/03-types-conversion.md --- episodes/03-types-conversion.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/episodes/03-types-conversion.md b/episodes/03-types-conversion.md index 9de7c22ae..99449e0d3 100644 --- a/episodes/03-types-conversion.md +++ b/episodes/03-types-conversion.md @@ -220,7 +220,7 @@ variable_one is 2 and variable_two is 5 - Afterwards, `variable_two` is set to this new value and *is not dependent on `variable_one`* so its value does not automatically change when `variable_one` changes. -Some data types that we haven't encountered yet (e.g. _lists_, _dictionaries_, and _objects_) have "links" inside them so they behave somewhat differently when you assign values to their *contents*. An example of this is shown in [Episode 12: Lists](../11-lists.md#copying-or-not). Assigning a list value to a new variable is like copying and pasting a formula from one cell to another. When you update an item in that list with the new value, you're updating that canonical list. +Some data types that we haven't encountered yet (e.g. _lists_, _dictionaries_, and _objects_) have "links" inside them so they behave somewhat differently when you assign values to their *contents*. An example of this is shown in [Episode 12: Lists](../11-lists.md#copying-or-not). Assigning a list value to a new variable is like copying and pasting a formula from one cell to another. When you update an item in that list with the new value, you're updating that item in the original list as well. ::::::::::::::::::::::::::::::::::::::: challenge From cb76dd389540a61b13d35e86ba403dcc7cab99f4 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 29 Dec 2025 14:00:58 +0100 Subject: [PATCH 7/7] Remove spreadsheet analogy --- episodes/03-types-conversion.md | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/episodes/03-types-conversion.md b/episodes/03-types-conversion.md index 99449e0d3..c6b1a7175 100644 --- a/episodes/03-types-conversion.md +++ b/episodes/03-types-conversion.md @@ -175,17 +175,11 @@ three squared is 9.0 ## Assignment changes the value of a variable, it does not create links between variables. -- In the spreadsheet context, - - If we use a formula to connect one cell to another, - and update the latter, - the former updates automatically. - - In contrast, if we copy one cell and paste its contents into another cell, - the second cell will not update if the first cell changes. - To update the second cell, we would need to copy and paste again. -- Assignment (the `=` operator) in python works like copy and paste in spreadsheets - not like a spreadsheet formula connecting the two cells. - In other words, after a variable is used to assign a value to another variable, - reassigning the first variable does not change the second variable. +When there is a variable on the right side of `=`, +it uses the current value of that variable +to set the value of the variable on the left side. +After that value is set, adjusting one variable +doesn't impact the other. To demonstrate this: @@ -200,7 +194,7 @@ print('a is', a, 'and b is', b) a is 2 and b is 1 ``` -When `b = a` is run, `a`'s value (`1`) is assigned to `b`, but no ongoing link is created between `a` and `b`. +When `b = a` is run, `a`'s value (`1`) is "assigned" to `b`, but no ongoing link is created between `a` and `b`. Here is a slightly more complicated example involving computation on the second value: @@ -220,7 +214,7 @@ variable_one is 2 and variable_two is 5 - Afterwards, `variable_two` is set to this new value and *is not dependent on `variable_one`* so its value does not automatically change when `variable_one` changes. -Some data types that we haven't encountered yet (e.g. _lists_, _dictionaries_, and _objects_) have "links" inside them so they behave somewhat differently when you assign values to their *contents*. An example of this is shown in [Episode 12: Lists](../11-lists.md#copying-or-not). Assigning a list value to a new variable is like copying and pasting a formula from one cell to another. When you update an item in that list with the new value, you're updating that item in the original list as well. +Some data types that we haven't encountered yet (e.g. _lists_ and _dictionaries_) have "links" inside them so they behave somewhat differently when you assign values to their *contents*. An example of this is shown in [Episode 12: Lists](../11-lists.md#copying-or-not). ::::::::::::::::::::::::::::::::::::::: challenge