Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions _episodes/03-types-conversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,23 @@ 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:

~~~
a = 1
b = a
a = 2
print('a is', a, 'and b is', b)
~~~
{: .language-python}
~~~
a is 2 and b is 1
~~~
{: .output}

`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:

~~~
first = 1
Expand All @@ -207,6 +220,8 @@ first is 2 and second is 5
creates a new value, and assigns it to `second`.
* After that, `second` does not remember where it came from.

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.

> ## Fractions
>
> What type of value is 3.4?
Expand Down