|
335 | 335 |
|
336 | 336 | You see, in \python, we can test many objects for their truth value. |
337 | 337 | \pythonilIdx{True} and \pythonil{False} obviously have truth values \pythonilIdx{True} and \pythonilIdx{False}, respectively. |
338 | | -By default, other objects have truth value \pythonilIdx{True} unless it offers an explicit conversion to \pythonilIdx{bool}\footnote{% |
| 338 | +By default, another object has truth value \pythonilIdx{True} unless it offers an explicit conversion to \pythonilIdx{bool}\footnote{% |
339 | 339 | Via the dunder method \dunder{bool}, see later in \cref{sec:dunderMethodsOverview}.} % |
340 | 340 | that yields~\pythonilIdx{False} or has a length and that length is zero\footnote{% |
341 | 341 | Via the dunder method \dunder{len}, see later in \cref{sec:dunderMethodsOverview}.}. |
342 | | -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}). |
343 | | -Now, \pythonil{\"False\"} is not empty, i.e., has a length greater than~0. |
| 342 | +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 | +Now, \pythonil{\"False\"} is not an empty string. |
| 344 | +It has a length greater than~0. |
344 | 345 | Therefore, it has truth value \pythonilIdx{True}, meaning that \pythonil{bool(\"False\")}\pythonIdx{bool({\textquotedbl}False{\textquotedbl})} actually yields \pythonilIdx{True}! |
345 | | -The empty string, on the other hand, has a truth value of \pythonilIdx{False}, i.e., \pythonil{bool(\"\")}\pythonIdx{bool(\textquotedbl\textquotedbl)} gives us \pythonilIdx{False}. |
| 346 | +The empty string, on the other hand, has lengh zero. |
| 347 | +Therefore, it has a truth value of \pythonilIdx{False}, i.e., \pythonil{bool(\"\")}\pythonIdx{bool(\textquotedbl\textquotedbl)} gives us \pythonilIdx{False}. |
346 | 348 |
|
347 | 349 | It should be noted that these conversion functions also work with other datatypes. |
348 | 350 | 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