Streamline previous content

This commit is contained in:
Alexander Hess 2019-11-06 11:10:29 +01:00
commit 8fd14a614d
6 changed files with 413 additions and 404 deletions

View file

@ -19,7 +19,7 @@
}
},
"source": [
"In this chapter, we continue the study of the built-in data types. Building on our knowledge of numbers, the next layer consists of textual data that are modeled primarily with the `str` type in Python. `str` objects are naturally more \"complex\" than numerical objects as any text consists of an arbitrary and possibly large number of individual characters that may be chosen from any alphabet in the history of humankind. Luckily, Python abstracts away most of this complexity."
"In this chapter, we continue the study of the built-in data types. Building on our knowledge of numbers, the next layer consists of textual data that are modeled primarily with the `str` type in Python. `str` objects are naturally more \"complex\" than numeric objects as any text consists of an arbitrary and possibly large number of individual characters that may be chosen from any alphabet in the history of humankind. Luckily, Python abstracts away most of this complexity."
]
},
{
@ -80,7 +80,7 @@
{
"data": {
"text/plain": [
"140133793916176"
"140488988107952"
]
},
"execution_count": 2,
@ -737,14 +737,14 @@
}
},
"source": [
"The idea of a **sequence** is yet another *abstract* concept.\n",
"A **sequence** is yet another *abstract* concept (cf., *containers* and *iterables* in [Chapter 4](https://nbviewer.jupyter.org/github/webartifex/intro-to-python/blob/master/04_iteration.ipynb#Containers-vs.-Iterables)).\n",
"\n",
"It unifies *four* [orthogonal](https://en.wikipedia.org/wiki/Orthogonality) (i.e., \"independent\") *abstract* concepts into one: Any *concrete* data type, such as `str`, is considered a sequence if it simultaneously\n",
"It unifies *four* [orthogonal](https://en.wikipedia.org/wiki/Orthogonality) (i.e., \"independent\") behaviors into one idea: Any data type, such as `str`, is considered a sequence if it simultaneously\n",
"\n",
"1. **contains** other \"things,\"\n",
"2. is **iterable**, and \n",
"3. comes with a *predictable* **order** of its\n",
"4. **finite** number of elements.\n",
"4. **finite** number of \"things.\"\n",
"\n",
"[Chapter 7](https://nbviewer.jupyter.org/github/webartifex/intro-to-python/blob/master/07_sequences.ipynb#Collections-vs.-Sequences) formalizes sequences in great detail. Here, we keep our focus on the `str` type that historically received its name as it models a \"**[string of characters](https://en.wikipedia.org/wiki/String_%28computer_science%29)**,\" and a \"string\" is more formally called a sequence in the computer science literature.\n",
"\n",
@ -1441,7 +1441,7 @@
}
},
"source": [
"Whereas elements of a `list` object *may* be *re-assigned*, as shortly hinted at in [Chapter 1](https://nbviewer.jupyter.org/github/webartifex/intro-to-python/blob/master/01_elements.ipynb#Who-am-I?-And-how-many?), this is *not* allowed for `str` objects. Once created, they *cannot* be *changed*. Formally, we say that they are **immutable**. In that regard, `str` objects and all the numerical types in [Chapter 5](https://nbviewer.jupyter.org/github/webartifex/intro-to-python/blob/master/05_numbers.ipynb) are alike.\n",
"Whereas elements of a `list` object *may* be *re-assigned*, as shortly hinted at in [Chapter 1](https://nbviewer.jupyter.org/github/webartifex/intro-to-python/blob/master/01_elements.ipynb#Who-am-I?-And-how-many?), this is *not* allowed for `str` objects. Once created, they *cannot* be *changed*. Formally, we say that they are **immutable**. In that regard, `str` objects and all the numeric types in [Chapter 5](https://nbviewer.jupyter.org/github/webartifex/intro-to-python/blob/master/05_numbers.ipynb) are alike.\n",
"\n",
"On the contrary, objects that may be changed after creation, are called **mutable**. We already saw in [Chapter 1](https://nbviewer.jupyter.org/github/webartifex/intro-to-python/blob/master/01_elements.ipynb#Who-am-I?-And-how-many?) how mutable objects are more difficult to reason about for a beginner, in particular, if more than *one* variable point to one. Yet, mutability does have its place in a programmer's toolbox, and we revisit this idea in the next chapters.\n",
"\n",
@ -1533,7 +1533,7 @@
{
"data": {
"text/plain": [
"140133784610832"
"140488987187120"
]
},
"execution_count": 46,
@ -1557,7 +1557,7 @@
{
"data": {
"text/plain": [
"140133793916176"
"140488988107952"
]
},
"execution_count": 47,
@ -1972,7 +1972,7 @@
{
"data": {
"text/plain": [
"140133891261864"
"140489068668384"
]
},
"execution_count": 61,
@ -2009,7 +2009,7 @@
{
"data": {
"text/plain": [
"140133784910848"
"140488987340848"
]
},
"execution_count": 63,