Skip to content

Commit b8f6b7f

Browse files
committed
added loops over collections
1 parent 5a7a8a9 commit b8f6b7f

File tree

5 files changed

+126
-20
lines changed

5 files changed

+126
-20
lines changed

bibliography/bibliography.bib

+1-1
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ @article{E1985AEOCF
972972
doi = {10.1007/BF01699475},
973973
url = {https://www.researchgate.net/publication/301720080},
974974
urldate = {2024-09-24},
975-
addendum = {Translation of of \cite{E1737DFCD}.},
975+
addendum = {Translation of~\cite{E1737DFCD}.},
976976
}
977977

978978
@incollection{EOEBSRGML2024LY,

text/main/basics/collections/collections.tex

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
\hsection{Collections}%
2+
\label{sec:collections}%
23
%
34
We already learned about simple datatypes, like integer and floating point numbers, strings, and Boolean values.
45
We also learned how we can use variables to store instances (objects) of such datatypes.

text/main/basics/collections/sets/sets.tex

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
\label{sec:sets}%
33
%
44
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{02_collections}{sets_1.py}{--args format}{sets:sets_1}{%
5-
A first example for using sets in \python: creating, modifying, and converting sets.}%
5+
A first example for using sets in \python: creating, modifying, and converting sets. %
6+
Since sets are unordered, printing them can yield a different result each time a program is executed (see \cref{bp:setsUnordered}).}%
67
%
78
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{02_collections}{sets_2.py}{--args format}{sets:sets_2}{%
8-
A second example for using sets in \python: creating sets and set operations (as illustrated in \cref{fig:setOperations}).}%
9+
A second example for using sets in \python: creating sets and set operations (as illustrated in \cref{fig:setOperations}). %
10+
Since sets are unordered, printing them can yield a different result each time a program is executed (see \cref{bp:setsUnordered}).}%
911
%
1012
\begin{figure}%
1113
\centering%

text/main/basics/simpleDataTypesAndOperations/str/str.tex

+9-6
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@
311311
%
312312
%
313313
\hsection{Escaping Characters}%
314+
\label{sec:str:escaping}%
315+
\pythonIdx{str!escaping}\pythonIdx{escaping}%
314316
%
315317
\noviceHint{%
316318
This section tells you how to include special characters in strings that you otherwise could not include, like quotation marks. %
@@ -320,7 +322,7 @@
320322
\begin{figure}%
321323
\centering%
322324
\includegraphics[width=0.8\linewidth]{\currentDir/strEscapes}%
323-
\caption{Escaping special characters in \python\ strings.}%
325+
\caption{Escaping special characters in \python\ strings.\pythonIdx{str!escaping}\pythonIdx{escaping}}%
324326
\label{fig:strEscapes}%
325327
\end{figure}%
326328
%
@@ -331,25 +333,25 @@
331333
Well, you can say, if I need a double quotation mark, then I will delimit my string with single quotation marks and vice versa.
332334
This is all good as long as you do not need \emph{both} single and double quotation marks inside the string.
333335

334-
The answer to this problem is \emph{escaping}\pythonIdx{str!escaping}.
336+
The answer to this problem is \emph{escaping}\pythonIdx{str!escaping}\pythonIdx{escaping}.
335337
The idea is very simple:
336338
If we need a certain quotation mark, then we simply put a backslash~(\inQuotes{\textbackslash})\pythonIdx{\textbackslash} before it.
337339
The backslash tells the \python\ interpreter that the next character should be considered as a normal character and not be interpreted as any special character, like a string delimiter.
338340

339-
In \cref{fig:strEscapes}, we present several strings with escape sequences.
341+
In \cref{fig:strEscapes}, we present several strings with escape sequences\pythonIdx{str!escaping}\pythonIdx{escaping}.
340342
For clarity reasons, we pass them to the \pythonilIdx{print} function to output them, which means that they show up undelimited in the console.
341343
A double quotation mark can be printed as \pythonil{print("\\"")}, i.e., as a string which is delimited and that then contains the escape sequence {\textbackslash\textquotedbl}\pythonIdx{\textbackslash\textquotedbl}.
342344
It then shows up as~\textil{"} in the output.
343345
A single quotation mark can be printed as \pythonil{print("\\'")}, i.e., via the escape sequence {\textbackslash\textquotesingle}\pythonIdx{\textbackslash\textquotesingle}.
344346
It appears as~\textil{'} in the output.
345347

346348
If the use the backslash character~\inQuotes{\textbackslash}\pythonIdx{\textbackslash} to escape characters which may otherwise have some special meaning {\dots} then what do we do if we need a backslash inside of a string?
347-
Easy: We escape it.
349+
Easy: We escape it\pythonIdx{str!escaping}\pythonIdx{escaping}.
348350
The escape sequence \inQuotes{\textbackslash\textbackslash}\pythonIdx{\textbackslash\textbackslash} is converted to a single backslash and \expandafter\pythonil{print("\\\\")} writes \textil{\\} to the output.
349351
Knowing these sequences, we can now try to \pythonil{print("\\"\\'\\\\")}.
350352
The result printed to the output then is~\textil{"'\\}.
351353

352-
Another situation where escape sequences are nice is when we want to have strings that span over multiple lines.
354+
Another situation where escape sequences are nice is when we want to have strings that span over multiple lines\pythonIdx{str!escaping}\pythonIdx{escaping}.
353355
The newline sequence \inQuotes{\textbackslash{n}}\pythonIdx{\textbackslash{n}} represents a \inQuotes{newline character} which causes the console to skip to the next line.
354356
\pythonil{print("Hello\\nWorld!")} will first print \textil{Hello}, then end the current line and begin a new line, and then print \textil{World!}.
355357
Notice that the newline character sequence \inQuotes{\textbackslash{n}} is used in \linux\ and similar systems, whereas \windows\ uses \inQuotes{\textbackslash{r}\textbackslash{n}}\pythonIdx{\textbackslash{r}\textbackslash{n}}.
@@ -361,14 +363,15 @@
361363
If you want to include a horizontal tabulator in a string, the escape sequence \inQuotes{\textbackslash{t}}\pythonIdx{\textbackslash{t}} is your friend:
362364
\pythonil{print("The horizontal tab is like a bigger space: '\\t'.")} yields \inlinelistingbox{\texttt{The~horizontal~tab~is~like~a~bigger~space:~'~~~~'.}}.
363365

364-
Finally, a backslash can also escape an actual newline in your string.
366+
Finally, a backslash can also escape an actual newline in your string\pythonIdx{str!escaping}\pythonIdx{escaping}.
365367
If you have a string that is too long to write on a single line but you do not want to have a linebreak inside the actual string, you can simply put a backslash, hit \keys{\enter}, and continue the typing the string.
366368
The linebreak will then be ignored entirely.
367369
Therefore, if you print~\pythonil{print("Hello\\}, hit \keys{\enter}, and then continue to write \pythonil{World!")}, this produces the output~\textil{HelloWorld!}.
368370

369371
Escape sequences allow us to write arbitrary text in strings.
370372
We already learned the sequences \inQuotes{\textbraceleft\textbraceleft}\pythonIdx{\textbraceleft\textbraceleft} and \inQuotes{\textbraceright\textbraceright}\pythonIdx{\textbraceright\textbraceright} that were designed for \pglspl{fstring} only.
371373
The backslash-based escape sequence we discussed in this section work for both \pglspl{fstring} and normal strings.%
374+
\pythonIdx{str!escaping}\pythonIdx{escaping}%
372375
\endhsection%
373376
%
374377
\hsection{Multi-Line Strings}%

0 commit comments

Comments
 (0)