[Tutor] toggle idiom?
dman
dman@dman.ddts.net
Wed, 8 May 2002 18:47:56 -0500
--yEPQxsgoJgBvi8ip
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On Wed, May 08, 2002 at 03:36:15PM -0700, Sean 'Shaleh' Perry wrote:
| > I would argue that
| > a =3D not a
| > is the best way of writing the original code because it clearly
| > shows the logic (as apposed to arithmetic) intent of the operation and
| > works for all cases the original works for. The only reason for using
| > the original instead of this is if a must be 0 or 1 in the end, rather
| > than simply a false or true value.
|=20
| is there a case where 'a =3D not a' will yield a value other than 0 or
| 1? i am not aware of one.
All boolean operations in CPython 2.3. (see PEP 285)
It is also the case in Java (boolean operations return a 'boolean' not
an 'int') and probably C++ as well.
I know you are referring to current python implementations (eg CPython
1.5.2, 2.0, 2.1, 2.2), but it _is_ implementation dependent. It is
never a good idea to rely on implementation dependent behavior if it
is avoidable. IMO it is more obscure to use boolean operators when
arithmetic results are required. Obscure code is not a good thing.
-D
--=20
Many a man claims to have unfailing love,
but a faithful man who can find?
Proverbs 20:6
=20
GnuPG key : http://dman.ddts.net/~dman/public_key.gpg
--yEPQxsgoJgBvi8ip
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iEYEARECAAYFAjzZuSwACgkQO8l8XBKTpRQPxgCeInbCVh2ulKqUpixGRpLvKb2H
0LoAoMRTTn6/6PKHn2AtjkuYG5zQw+Wf
=tawo
-----END PGP SIGNATURE-----
--yEPQxsgoJgBvi8ip--