Python's and and Pythons or
Chris Angelico
rosuav at gmail.com
Wed Oct 9 21:13:54 EDT 2013
On Thu, Oct 10, 2013 at 11:36 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Other languages (Ruby, PHP, Javascript, etc.) also have
> truthy and falsey values, but in my opinion none of them have got it
> right. Python has a unifying model of truthiness: objects which represent
> "something" ought to be truthy, those which represent "nothing" ought to
> be falsey
Python's model makes a lot of sense. The only other system that I've
seen that makes as much sense is Pike's, which can be summarized as:
Falsey:
0 (the integer; does the job of None in many contexts)
Truthy:
Everything else.
Python lets you distinguish easily between an empty list and a list
with something in it; Pike lets you distinguish between a list and the
absence of a list.
The use of 'and' and 'or' in returning their arguments is an extremely
useful one, but I'm not sure it has a name. Pike and Lua have the same
behaviour; neither offers a good term for it. Recommendation: Invent a
term if you can't find one, and start using it. :)
ChrisA
More information about the Python-list
mailing list