Streamline previous content
This includes shortening the filename of notebook 01
This commit is contained in:
parent
8e841274e6
commit
514b2dac40
4 changed files with 38 additions and 27 deletions
|
@ -429,7 +429,7 @@
|
|||
}
|
||||
},
|
||||
"source": [
|
||||
"Here is a brief history of and some background on Python:\n",
|
||||
"Here is a brief history of and some background on Python (cf., also this [TechRepublic article](https://www.techrepublic.com/article/python-is-eating-the-world-how-one-developers-side-project-became-the-hottest-programming-language-on-the-planet/) for a more elaborate story):\n",
|
||||
"\n",
|
||||
"- [Guido van Rossum](https://en.wikipedia.org/wiki/Guido_van_Rossum) (Python’s **[Benevolent Dictator for Life](https://en.wikipedia.org/wiki/Benevolent_dictator_for_life)**) was bored during a week around Christmas 1989 and started Python as a hobby project \"that would keep \\[him\\] occupied\" for some days\n",
|
||||
"- the idea was to create a **general-purpose scripting** language that would allow fast **prototyping** and would **run on every operating system**\n",
|
||||
|
@ -439,6 +439,17 @@
|
|||
"- the language is named after the sketch comedy group [Monty Python](https://en.wikipedia.org/wiki/Monty_Python)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"slideshow": {
|
||||
"slide_type": "skip"
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"#### Summary"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
|
@ -447,7 +458,7 @@
|
|||
}
|
||||
},
|
||||
"source": [
|
||||
"Python is a **general-purpose** programming language that allows for **fast development**, is **easy to comprehend**, **open-source**, long established, unifies the knowledge of **hundreds of thousands of experts** around the world, runs on basically every machine, and can handle the complexities of applications involving **big data**."
|
||||
"Python is a **general-purpose** programming language that allows for **fast development**, is **easy to read**, **open-source**, long established, unifies the knowledge of **hundreds of thousands of experts** around the world, runs on basically every machine, and can handle the complexities of applications involving **big data**."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -770,7 +781,7 @@
|
|||
" 1. Elements of a Program\n",
|
||||
" 2. Functions & Modularization\n",
|
||||
"- What is the flow of execution? How can we form sentences from words?\n",
|
||||
" 3. Boolean Logic & Conditionals\n",
|
||||
" 3. Conditionals & Exceptions\n",
|
||||
" 4. Recursion & Looping"
|
||||
]
|
||||
},
|
||||
|
@ -813,7 +824,7 @@
|
|||
}
|
||||
},
|
||||
"source": [
|
||||
"As with every good lecture, there has to be a [xkcd](https://xkcd.com/353/) comic somewhere."
|
||||
"As with every good book, there has to be a [xkcd](https://xkcd.com/353/) comic somewhere."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -742,7 +742,7 @@
|
|||
}
|
||||
},
|
||||
"source": [
|
||||
"The normal order of precedence from mathematics applies (i.e., \"PEMDAS\" rule) but parentheses help avoid confusion."
|
||||
"The normal [order of precedence](https://docs.python.org/3/reference/expressions.html#operator-precedence) from mathematics applies (i.e., \"PEMDAS\" rule) but parentheses help avoid confusion."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -949,7 +949,7 @@
|
|||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"139867825605456"
|
||||
"139940106427216"
|
||||
]
|
||||
},
|
||||
"execution_count": 27,
|
||||
|
@ -973,7 +973,7 @@
|
|||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"139867825776440"
|
||||
"139940106602344"
|
||||
]
|
||||
},
|
||||
"execution_count": 28,
|
||||
|
@ -997,7 +997,7 @@
|
|||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"139867825460912"
|
||||
"139940105769456"
|
||||
]
|
||||
},
|
||||
"execution_count": 29,
|
||||
|
@ -1041,7 +1041,7 @@
|
|||
}
|
||||
},
|
||||
"source": [
|
||||
"`a` and `d` indeed have the same value as can be checked with the **equality operator** `==`. The resulting `True` (and the `False` below) is yet another data type, a so-called **boolean**."
|
||||
"`a` and `d` indeed have the same value as can be checked with the **equality operator** `==`. The resulting `True` (and the `False` below) is yet another data type, a so-called **boolean**. We will look into that closely in Chapter 3."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -1780,7 +1780,7 @@
|
|||
" "
|
||||
],
|
||||
"text/plain": [
|
||||
"<IPython.lib.display.YouTubeVideo at 0x7f358405d550>"
|
||||
"<IPython.lib.display.YouTubeVideo at 0x7f46584be518>"
|
||||
]
|
||||
},
|
||||
"execution_count": 50,
|
||||
|
@ -2087,7 +2087,7 @@
|
|||
}
|
||||
},
|
||||
"source": [
|
||||
"A variable can be **re-assigned** as often as we wish. Thereby, we could also assign an object of a different type. Because this is allowed, Python is said to be a **dynamically typed** language. On the contrary, a **statically typed** language like C also allows re-assignment but only with objects of the same type. This subtle distinction is one reason why Python is slower at execution than C: As it runs a program, it needs to figure out an object's type each time it is referenced. But as mentioned before, this can be mitigated with third-party libraries."
|
||||
"A variable can be **re-assigned** as often as we wish. Thereby, we could also assign an object of a *different* type. Because this is allowed, Python is said to be a **dynamically typed** language. On the contrary, a **statically typed** language like C also allows re-assignment but only with objects of the *same* type. This subtle distinction is one reason why Python is slower at execution than C: As it runs a program, it needs to figure out an object's type each time it is referenced. But as mentioned before, this can be mitigated with third-party libraries."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -2209,7 +2209,7 @@
|
|||
}
|
||||
},
|
||||
"source": [
|
||||
"Variables can be **[de-referenced](https://docs.python.org/3/reference/simple_stmts.html#the-del-statement)** (i.e., \"deleted\") with the `del` statement. This does *not* delete the object to which a variable points to. It merely removes the variable from the \"list of all variables\"."
|
||||
"Variables can be **[de-referenced](https://docs.python.org/3/reference/simple_stmts.html#the-del-statement)** (i.e., \"deleted\") with the `del` statement. This does *not* delete the object to which a variable points to. It merely removes the variable's name from the \"global list of all names\"."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -2257,7 +2257,7 @@
|
|||
}
|
||||
},
|
||||
"source": [
|
||||
"If we refer to an unknown name, a runtime error occurs, namely a `NameError`."
|
||||
"If we refer to an unknown name, a *runtime* error occurs, namely a `NameError`. The `Name` in `NameError` gives a hint as to why we prefer the term *name* over *identifier*: Python just uses it more often in its error messages."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -2293,7 +2293,7 @@
|
|||
}
|
||||
},
|
||||
"source": [
|
||||
"Some variables magically exist when we start Python. In this introductory book, we can safely ignore them."
|
||||
"Some variables magically exist when we start a Python process or are added by Jupyter. We can safely ignore the former until Chapter 10 and the latter for good."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -2740,7 +2740,7 @@
|
|||
"source": [
|
||||
"Let's change the first element of `x`.\n",
|
||||
"\n",
|
||||
"Chapter 7 discusses lists in more depth. For now, let's just view a `list` object as some sort of **container** that holds an arbitrary number of pointers to other objects and treat brackets `[]` attached to it as just another operator, called the **indexing operator**. `x[0]` instructs Python to first follow the pointer from the \"global\" directory of all names to the `x` object. Then, it follows the first pointer it finds there to the `1` object. The indexing operator must be an operator as we merely read the first element and do not change anything in memory.\n",
|
||||
"Chapter 7 discusses lists in more depth. For now, let's just view a `list` object as some sort of **container** that holds an arbitrary number of pointers to other objects and treat the brackets `[]` attached to it as just another operator, called the **indexing operator**. `x[0]` instructs Python to first follow the pointer from the global list of all names to the `x` object. Then, it follows the first pointer it finds there to the `1` object. The indexing operator must be an operator as we merely read the first element and do not change anything in memory.\n",
|
||||
"\n",
|
||||
"Note how Python **begins counting at 0**. This is not the case for many other languages, for example, [MATLAB](https://en.wikipedia.org/wiki/MATLAB), [R](https://en.wikipedia.org/wiki/R_%28programming_language%29), or [Stata](https://en.wikipedia.org/wiki/Stata). To understand why this makes sense, see this short [note](https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html) by one of the all-time greats in computer science, the late [Edsger Dijkstra](https://en.wikipedia.org/wiki/Edsger_W._Dijkstra)."
|
||||
]
|
||||
|
@ -2777,7 +2777,7 @@
|
|||
}
|
||||
},
|
||||
"source": [
|
||||
"To change the first entry in the list, we use the assignment statement `=` again. Here, this does actually *not* create a *new* variable (or overwrite an existing one) but only changes the object to which the first pointer in the `x` list points to. As we only change parts of the `x` object, we say that we **mutate** (i.e., change) its **state**."
|
||||
"To change the first entry in the list, we use the assignment statement `=` again. Here, this does actually *not* create a *new* variable (or overwrite an existing one) but only changes the object to which the first pointer in the `x` list points to. As we only change parts of the `x` object, we say that we **mutate** (i.e., \"change\") its **state**. To use the bag analogy from above, we keep the same bag but \"flip\" some of the $0$s into $1$s and some of the $1$s into $0$s."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -2890,9 +2890,9 @@
|
|||
}
|
||||
},
|
||||
"source": [
|
||||
"**[Phil Karlton](https://skeptics.stackexchange.com/questions/19836/has-phil-karlton-ever-said-there-are-only-two-hard-things-in-computer-science)** famously noted (during his time at [Netscape](https://en.wikipedia.org/wiki/Netscape)):\n",
|
||||
"[Phil Karlton](https://skeptics.stackexchange.com/questions/19836/has-phil-karlton-ever-said-there-are-only-two-hard-things-in-computer-science) famously noted during his time at [Netscape](https://en.wikipedia.org/wiki/Netscape):\n",
|
||||
"\n",
|
||||
"> \"There are two hard problems in computer science: naming things and cache invalidation ... and off-by-one errors.\""
|
||||
"> \"There are *two* hard problems in computer science: *naming things* and *cache invalidation* ... and *off-by-one* errors.\""
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -3077,7 +3077,7 @@
|
|||
}
|
||||
},
|
||||
"source": [
|
||||
"Variables with leading and trailing double underscores, referred to as **dunder** in Python \"slang\", are used for important built-in variables. Do *not* use this style for custom variables!"
|
||||
"Variables with leading and trailing double underscores, referred to as **dunder** in Python jargon, are used for important built-in functionalities. Do *not* use this style for custom variables unless you know exactly what you are doing!"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -3123,7 +3123,7 @@
|
|||
}
|
||||
},
|
||||
"source": [
|
||||
"This PyCon talk by [Ned Batchelder](https://nedbatchelder.com/) (a software engineer at [edX](https://www.edx.org/) and the organizer of the [Python User Group](https://www.meetup.com/bostonpython/) in Boston) summarizes all situations where some sort of variable assignment is done in Python. The content is intermediate and therefore it is ok if you do not understand everything at this point. However, the contents should be known by everyone claiming to be a Pythonista."
|
||||
"This PyCon talk by [Ned Batchelder](https://nedbatchelder.com/), a well-known Pythonista and the organizer of the [Python User Group](https://www.meetup.com/bostonpython/) in Boston, summarizes all situations where some sort of variable assignment is done in Python. The content is intermediate and therefore it is ok if you do not understand everything at this point. However, the contents should be known by everyone claiming to be proficient in Python."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -3150,7 +3150,7 @@
|
|||
" "
|
||||
],
|
||||
"text/plain": [
|
||||
"<IPython.lib.display.YouTubeVideo at 0x7f35840cfe48>"
|
||||
"<IPython.lib.display.YouTubeVideo at 0x7f465852de48>"
|
||||
]
|
||||
},
|
||||
"execution_count": 93,
|
|
@ -142,7 +142,7 @@
|
|||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"140620654002656"
|
||||
"139655430681056"
|
||||
]
|
||||
},
|
||||
"execution_count": 3,
|
||||
|
@ -635,7 +635,7 @@
|
|||
"source": [
|
||||
"Code gets even more confusing when variables by the same name from different scopes collide. In particular, what should we expect to happen if a function changes a globally defined variable internally?\n",
|
||||
"\n",
|
||||
"`average_odds()` below works like `average_evens()` above except that it **[casts](https://en.wikipedia.org/wiki/Type_conversion)** (i.e., \"converts\") the elements of `numbers` as objects of type `int` with the [int()](https://docs.python.org/3/library/functions.html#int) built-in first before filtering and averaging them. In doing so, it introduces an *internal* variable `nums` whose name collides with the one in the global scope."
|
||||
"`average_odds()` below works like `average_evens()` above except that it **[casts](https://en.wikipedia.org/wiki/Type_conversion)** (i.e., \"converts\") the elements of `numbers` as objects of type `int` with the [int()](https://docs.python.org/3/library/functions.html#int) built-in first before filtering and averaging them. In doing so, it introduces an *internal* variable `nums` whose name collides with the one in the global scope. The **inequality operator** `!=` is just the **reversed** version of `==`."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -658,7 +658,7 @@
|
|||
" float: average\n",
|
||||
" \"\"\"\n",
|
||||
" nums = [int(n) for n in numbers] # cast all numbers as integers first\n",
|
||||
" odds = [n for n in nums if n % 2 != 0] # before filtering them\n",
|
||||
" odds = [n for n in nums if n % 2 != 0] # before filtering for odd numbers\n",
|
||||
" average = sum(odds) / len(odds)\n",
|
||||
" return average"
|
||||
]
|
||||
|
@ -2036,7 +2036,7 @@
|
|||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"140620734513624"
|
||||
"139655519584648"
|
||||
]
|
||||
},
|
||||
"execution_count": 58,
|
||||
|
@ -2649,7 +2649,7 @@
|
|||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"0.4028601552264015"
|
||||
"0.12717011866176486"
|
||||
]
|
||||
},
|
||||
"execution_count": 75,
|
||||
|
@ -2684,7 +2684,7 @@
|
|||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"<bound method Random.choice of <random.Random object at 0x561d3c7fbba8>>"
|
||||
"<bound method Random.choice of <random.Random object at 0x562161984ba8>>"
|
||||
]
|
||||
},
|
||||
"execution_count": 76,
|
||||
|
|
Loading…
Reference in a new issue