Skip to content

Commit fef2f72

Browse files
committed
further slight clarification
1 parent 17cad53 commit fef2f72

File tree

1 file changed

+9
-1
lines changed
  • text/main/basics/simpleDataTypesAndOperations/str

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,19 @@
340340
that yields~\pythonilIdx{False} or has a length and that length is zero\footnote{%
341341
Via the dunder method \dunder{len}, see later in \cref{sec:dunderMethodsOverview}.}.
342342
Other objects that have a truth value of \pythonilIdx{False} are numeric types which are zero, such as \pythonil{0} and \pythonil{0.0} as well as empty collections~(which we learn about a bit later in \cref{sec:collections}) or the empty string.
343+
344+
Strings by themselves do not support an explicit conversation to the type \pythonil{bool}.
345+
The function \pythonil{bool} thus has to figure out the truth value by itself.
346+
However, strings do have a length, as we already learned.
347+
You can get the length via the \pythonilIdx{len} function.
343348
Now, \pythonil{\"False\"} is not an empty string.
344349
It has a length greater than~0.
345-
Therefore, it has truth value \pythonilIdx{True}, meaning that \pythonil{bool(\"False\")}\pythonIdx{bool({\textquotedbl}False{\textquotedbl})} actually yields \pythonilIdx{True}!
350+
\pythonil{len(\"False\")} gives us~5.
351+
Therefore, \pythonil{\"False\"} has truth value \pythonilIdx{True}, meaning that \pythonil{bool(\"False\")}\pythonIdx{bool({\textquotedbl}False{\textquotedbl})} actually yields \pythonilIdx{True}!
352+
346353
The empty string, on the other hand, has lengh zero.
347354
Therefore, it has a truth value of \pythonilIdx{False}, i.e., \pythonil{bool(\"\")}\pythonIdx{bool(\textquotedbl\textquotedbl)} gives us \pythonilIdx{False}.
355+
Any other string, for example \pythonil{\"blabla\"} is also none-empty and thus has truth value \pythonil{True}.
348356

349357
It should be noted that these conversion functions also work with other datatypes.
350358
For example, \pythonil{float(0)} converts the integer~\pythonil{0} to the \pythonil{float} value~\pythonil{0.0} and \pythonilIdx{bool(0)} gives us \pythonilIdx{False}.

0 commit comments

Comments
 (0)