[issue46883] Add glossary entries to clarify the true/True and false/False distinction

2022-02-28 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

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

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46883] Add glossary entries to clarify the true/True and false/False distinction

2022-02-28 Thread Steven D'Aprano


New submission from Steven D'Aprano :

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.

--
assignee: docs@python
components: Documentation
messages: 414204
nosy: docs@python, steven.daprano
priority: normal
severity: normal
status: open
title: Add glossary entries to clarify the true/True and false/False distinction
type: enhancement
versions: Python 3.10, Python 3.11, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com