Streamline previous content
This commit is contained in:
parent
fe13817605
commit
ca8fefdce1
13 changed files with 3595 additions and 1913 deletions
|
|
@ -19,7 +19,7 @@
|
|||
}
|
||||
},
|
||||
"source": [
|
||||
"We analyzed every aspect of the `average_evens()` function in [Chapter 2](https://nbviewer.jupyter.org/github/webartifex/intro-to-python/blob/master/02_functions.ipynb) except for the `if` related parts. While it seems to do what we expect it to, there is a whole lot more we learn from taking it apart. In particular, the `if` may occur within both a **statement** or an **expression**, analogous as to how a noun in a natural language is *either* the subject of *or* an object in a sentence. What is common to both usages is that it leads to code being executed for *parts* of the input only. It is our first way of **controlling** the **flow of execution** in a program.\n",
|
||||
"We analyzed every aspect of the `average_evens()` function in [Chapter 2](https://nbviewer.jupyter.org/github/webartifex/intro-to-python/blob/master/02_functions.ipynb) except for the `if`-related parts. While it seems to do what we expect it to, there is a whole lot more we learn from taking it apart. In particular, the `if` may occur within both a **statement** or an **expression**, analogous as to how a noun in a natural language is *either* the subject of *or* an object in a sentence. What is common to both usages is that it leads to code being executed for *parts* of the input only. It is our first way of **controlling** the **flow of execution** in a program.\n",
|
||||
"\n",
|
||||
"After deconstructing `if` in the first part of this chapter, we take a close look at a similar concept, namely handling **exceptions**."
|
||||
]
|
||||
|
|
@ -189,7 +189,7 @@
|
|||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"94711290794976"
|
||||
"93918328484832"
|
||||
]
|
||||
},
|
||||
"execution_count": 5,
|
||||
|
|
@ -213,7 +213,7 @@
|
|||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"94711290794944"
|
||||
"93918328484800"
|
||||
]
|
||||
},
|
||||
"execution_count": 6,
|
||||
|
|
@ -313,7 +313,7 @@
|
|||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"94711290781936"
|
||||
"93918328471792"
|
||||
]
|
||||
},
|
||||
"execution_count": 10,
|
||||
|
|
@ -357,7 +357,7 @@
|
|||
}
|
||||
},
|
||||
"source": [
|
||||
"`True`, `False`, and `None` have the property that they each exist in memory only *once*. Objects designed this way are so-called **singletons**. This **[design pattern](https://en.wikipedia.org/wiki/Design_Patterns)** was originally developed to keep a program's memory usage at a minimum. It may only be employed in situations where we know that an object does *not* mutate its value (i.e., to re-use the bag analogy from [Chapter 1](https://nbviewer.jupyter.org/github/webartifex/intro-to-python/blob/master/01_elements.ipynb#Objects-vs.-Types-vs.-Values), no flipping of $0$s and $1$s in the bag is allowed). In languages \"closer\" to the memory like C, we would have to code this singleton logic ourselves, but Python has this built in for *some* types.\n",
|
||||
"`True`, `False`, and `None` have the property that they each exist in memory only *once*. Objects designed this way are so-called **singletons**. This **[design pattern](https://en.wikipedia.org/wiki/Design_Patterns)** was originally developed to keep a program's memory usage at a minimum. It may only be employed in situations where we know that an object does *not* mutate its value (i.e., to reuse the bag analogy from [Chapter 1](https://nbviewer.jupyter.org/github/webartifex/intro-to-python/blob/master/01_elements.ipynb#Objects-vs.-Types-vs.-Values), no flipping of $0$s and $1$s in the bag is allowed). In languages \"closer\" to the memory like C, we would have to code this singleton logic ourselves, but Python has this built in for *some* types.\n",
|
||||
"\n",
|
||||
"We verify this with either the `is` operator or by comparing memory addresses."
|
||||
]
|
||||
|
|
@ -418,7 +418,7 @@
|
|||
}
|
||||
},
|
||||
"source": [
|
||||
"So the following expression regards *four* objects in memory: *One* `list` object holding ten pointers to *three* other objects."
|
||||
"So the following expression regards *four* objects in memory: *One* `list` object holding ten references to *three* other objects."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue