On 27/06/2016 00:22, Gregory Ewing wrote:
BartC wrote:
On 26/06/2016 08:36, Lawrence D’Oliveiro wrote:

One of Python’s few mistakes was that it copied the C convention of
using “=” for assignment and “==” for equality comparison.

One of C's many mistakes. Unfortunately C has been very influential.

I'm not sure it's fair to call it a mistake. C was
designed for expert users, and a tradeoff was likely
made based on the observation that assignment is
used much more often than equality testing.

You mean the rationale was based on saving keystrokes?

A shame they didn't consider that when requiring parentheses around conditionals, semicolons, /*...*/ around comments, %d format codes and elaborate for-statements then!

But you might be right in that it was probably based on existing usage of Fortran, PL/I and maybe even Basic. (Its predecessor 'B' used "=", but B came through BCPL which I believe used ":="; perhaps the mistake was in discarding that.)

However, why couldn't Python have used "=" both for assignment, and
for equality?

Because an expression on its own is a valid statement,
so

   a = b

would be ambiguous as to whether it meant assigning b
to a or evaluating a == b and discarding the result.

And that would be another reason why == is needed for equality.

--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to