Skip to content

Commit 0672e50

Browse files
committed
Update the HTML Book
1 parent 9edfb7e commit 0672e50

20 files changed

+112
-77
lines changed

book3/zips/html.zip

1.26 KB
Binary file not shown.

html3/01-intro.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,11 @@
157157
div.columns{display: flex; gap: min(4vw, 1.5em);}
158158
div.column{flex: auto; overflow-x: auto;}
159159
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
160-
ul.task-list{list-style: none;}
160+
/* The extra [class] is a hack that increases specificity enough to
161+
override a similar rule in reveal.js */
162+
ul.task-list[class]{list-style: none;}
161163
ul.task-list li input[type="checkbox"] {
164+
font-size: inherit;
162165
width: 0.8em;
163166
margin: 0 0.8em 0.2em -1.6em;
164167
vertical-align: middle;

html3/02-variables.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;

html3/03-conditional.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;

html3/04-functions.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;

html3/05-iterations.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;

html3/06-strings.php

Lines changed: 26 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;
@@ -506,55 +509,36 @@ class="uri">https://docs.python.org/library/stdtypes.html#string-methods</a></p>
506509
<p><a
507510
href="https://docs.python.org/library/stdtypes.html#string-methods"
508511
class="uri">https://docs.python.org/library/stdtypes.html#string-methods</a>.</p>
509-
<h2 id="format-operator">Format operator</h2>
510-
<p> </p>
511-
<p>The <em>format operator</em>, <code>%</code> allows us to construct
512-
strings, replacing parts of the strings with the data stored in
513-
variables. When applied to integers, <code>%</code> is the modulus
514-
operator. But when the first operand is a string, <code>%</code> is the
515-
format operator.</p>
516-
<p></p>
517-
<p>The first operand is the <em>format string</em>, which contains one
518-
or more <em>format sequences</em> that specify how the second operand is
519-
formatted. The result is a string.</p>
512+
<h2 id="formatted-string-literals">Formatted String Literals</h2>
520513
<p></p>
521-
<p>For example, the format sequence <code>%d</code> means that the
522-
second operand should be formatted as an integer (“d” stands for
523-
“decimal”):</p>
514+
<p>A formatted string literal (often referred to simply as an f-string)
515+
allows Python expressions to be used within string literals. This is
516+
accomplished by prepending an <code>f</code> to the string literal and
517+
enclosing expressions in curly braces <code>{}</code>.</p>
518+
<p>For example, wrapping a variable name in curly braces inside an
519+
f-string will cause it to be replaced by its value:</p>
524520
<pre class="python"><code>&gt;&gt;&gt; camels = 42
525-
&gt;&gt;&gt; &#39;%d&#39; % camels
521+
&gt;&gt;&gt; f&#39;{camels}&#39;
526522
&#39;42&#39;</code></pre>
527523
<p>The result is the string ‘42’, which is not to be confused with the
528524
integer value 42.</p>
529-
<p>A format sequence can appear anywhere in the string, so you can embed
530-
a value in a sentence:</p>
525+
<p>An expression can appear anywhere in the string, so you can embed a
526+
value in a sentence:</p>
531527
<pre class="python"><code>&gt;&gt;&gt; camels = 42
532-
&gt;&gt;&gt; &#39;I have spotted %d camels.&#39; % camels
528+
&gt;&gt;&gt; f&#39;I have spotted {camels} camels.&#39;
533529
&#39;I have spotted 42 camels.&#39;</code></pre>
534-
<p>If there is more than one format sequence in the string, the second
535-
argument has to be a tuple<a href="#fn1" class="footnote-ref"
536-
id="fnref1" role="doc-noteref"><sup>1</sup></a>. Each format sequence is
537-
matched with an element of the tuple, in order.</p>
538-
<p>The following example uses <code>%d</code> to format an integer,
539-
<code>%g</code> to format a floating-point number (don’t ask why), and
540-
<code>%s</code> to format a string:</p>
541-
<pre class="python"><code>&gt;&gt;&gt; &#39;In %d years I have spotted %g %s.&#39; % (3, 0.1, &#39;camels&#39;)
530+
<p>Several expressions can be included within a single string literal in
531+
order to create more complex strings.</p>
532+
<pre class="python"><code>&gt;&gt;&gt; years = 3
533+
&gt;&gt;&gt; count = .1
534+
&gt;&gt;&gt; species = &#39;camels&#39;
535+
&gt;&gt;&gt; f&#39;In {years} years I have spotted {count} {species}.&#39;
542536
&#39;In 3 years I have spotted 0.1 camels.&#39;</code></pre>
543-
<p>The number of elements in the tuple must match the number of format
544-
sequences in the string. The types of the elements also must match the
545-
format sequences:</p>
546-
<p> </p>
547-
<pre class="python"><code>&gt;&gt;&gt; &#39;%d %d %d&#39; % (1, 2)
548-
TypeError: not enough arguments for format string
549-
&gt;&gt;&gt; &#39;%d&#39; % &#39;dollars&#39;
550-
TypeError: %d format: a number is required, not str</code></pre>
551-
<p>In the first example, there aren’t enough elements; in the second,
552-
the element is the wrong type.</p>
553-
<p>The format operator is powerful, but it can be difficult to use. You
554-
can read more about it at</p>
537+
<p>Formatted string literals are powerful, and they can do even more
538+
than is covered here. You can read more about them at</p>
555539
<p><a
556-
href="https://docs.python.org/library/stdtypes.html#printf-style-string-formatting"
557-
class="uri">https://docs.python.org/library/stdtypes.html#printf-style-string-formatting</a>.</p>
540+
href="https://docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals"
541+
class="uri">https://docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals</a>.</p>
558542
<h2 id="debugging">Debugging</h2>
559543
<p></p>
560544
<p>A skill that you should cultivate as you program is always asking
@@ -684,7 +668,7 @@ class="uri">https://docs.python.org/library/stdtypes.html#printf-style-string-fo
684668
<p> </p>
685669
<p><strong>Exercise 6: Read the documentation of the string methods at
686670
<a href="https://docs.python.org/library/stdtypes.html#string-methods"
687-
class="uri">https://docs.python.org/library/stdtypes.html#string-methods</a>
671+
class="uri">https://docs.python.org/library/stdtypes.html#string-methods</a>.
688672
You might want to experiment with some of them to make sure you
689673
understand how they work. <code>strip</code> and <code>replace</code>
690674
are particularly useful.</strong></p>
@@ -693,15 +677,6 @@ class="uri">https://docs.python.org/library/stdtypes.html#string-methods</a>
693677
indicate optional arguments. So <code>sub</code> is required, but
694678
<code>start</code> is optional, and if you include <code>start</code>,
695679
then <code>end</code> is optional.</strong></p>
696-
<aside id="footnotes" class="footnotes footnotes-end-of-document"
697-
role="doc-endnotes">
698-
<hr />
699-
<ol>
700-
<li id="fn1"><p>A tuple is a sequence of comma-separated values inside a
701-
pair of parenthesis. We will cover tuples in Chapter 10<a href="#fnref1"
702-
class="footnote-back" role="doc-backlink">↩︎</a></p></li>
703-
</ol>
704-
</aside>
705680
</body>
706681
</html>
707682
<?php if ( file_exists("../bookfoot.php") ) {

html3/07-files.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;

html3/08-lists.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;
@@ -701,7 +704,7 @@ class="math inline"><em>n</em></span> is the length of the list. Each
701704
<li><p>Lists, <code>split</code>, and files</p>
702705
<p>When we read and parse files, there are many opportunities to
703706
encounter input that can crash our program so it is a good idea to
704-
revisit the <em>guardian</em> pattern when it comes writing programs
707+
revisit the <em>guardian</em> pattern when it comes to writing programs
705708
that read through a file and look for a “needle in the haystack”.</p>
706709
<p>Let’s revisit our program that is looking for the day of the week on
707710
the from lines of our file:</p>

html3/09-dictionaries.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;

0 commit comments

Comments
 (0)