[Python-Dev] "and" and "or" operators in Py3.0

Gareth McCaughan gmccaughan at synaptics-uk.com
Tue Sep 20 13:16:53 CEST 2005


On Tuesday 2005-09-20 11:40, Raymond Hettinger wrote:
> > > 2) When going back and forth between languages, it is easy to forget
> > > that only Python returns something other than a boolean.
> > 
> > As others point out, this isn't true.
> 
> In C, C++, C#, Java, and JavaScript, what do you get when you print the
> result of 3 || 10?

JavaScript does the same as Python, according to section 11.11 of
the EMCA standard as of December 1999, which is what I have to hand.

The others you mention don't, because doing so would fit very
uncomfortably with their static type systems.

Those are not the only languages that exist other than Python.
Perl and Ruby both have Python-like behaviour in this respect.
So do all the Lisp variants I can readily check (CL, elisp,
Scheme, Dylan). So does Lua.

I can't, offhand, think of any dynamically typed language that
doesn't behave this way. Oh, except Smalltalk, which has a
radically different approach to the whole business.

-- 
g



More information about the Python-Dev mailing list