This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add glossary entries to clarify the true/True and false/False distinction
Type: enhancement Stage:
Components: Documentation Versions: Python 3.11, Python 3.10, Python 3.9, Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, steven.daprano
Priority: normal Keywords:

Created on 2022-02-28 15:18 by steven.daprano, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg414204 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2022-02-28 15:18
There is a long-standing tradition, going back to Python 1.x days before we had dedicated True and False values, to use the lowercase "true" and "false" to mean *any value that duck-types as True* and *any value that duck-types as False* in a boolean context.

Other terms for this same concept include "truthy/falsey" and using true/false as adjectives rather than nouns, e.g. "a true value".

But I am not sure whether this is actually written down anywhere in the documentation.

It would be useful for those who are not aware of the convention (e.g. beginners and people coming from other languages) if the Glossary had entries for lowercase "true" and "false" that explained the usage and referred back to PEP 285. See for example #46882 where this came up.

I suggest something like the following:

boolean context
  Code such as ``if condition:`` and ``while condition:`` which causes the expression ``condition`` to be evaluated as if it were a :class:`bool`.

false
  Any object which evaluates to the :class:`bool` singleton ``False`` in a :term:`boolean context`. Informally known as "falsey". See :term:`true` and :pep:`285`. Among the builtins , false values include ``None``, empty containers and strings, and zero numbers.

true
  Any object which evaluates to the :class:`bool` singleton ``True`` in a :term:`boolean context`. Informally known as "truthy". See :term:`false` and :pep:`285`. Among the builtins , true values include non-empty containers and strings, non-zero numbers (including NANs), and all other objects by default.
msg414206 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2022-02-28 15:29
Note also that this is mentioned here:

https://docs.python.org/3/library/stdtypes.html#boolean-values

"[True and False] are used to represent truth values (although other values can also be considered false or true)."

although it is perhaps not as clear as I would prefer.

Also relevant is this:

https://docs.python.org/3/library/stdtypes.html#truth-value-testing
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 91039
2022-02-28 15:29:38steven.dapranosetmessages: + msg414206
2022-02-28 15:18:18steven.dapranocreate