sequence multiplied by -1

John Nagle nagle at animats.com
Sun Sep 26 01:08:54 EDT 2010


On 9/25/2010 4:45 AM, Thomas Jollans wrote:
> On Saturday 25 September 2010, it occurred to Yingjie Lan to exclaim:
>> Hi,
>>
>> I noticed that in python3k, multiplying a sequence by a negative integer is
>> the same as multiplying it by 0, and the result is an empty sequence. It
>> seems to me that there is a more meaningful symantics.

    The concept that the multiply operator should be overloaded to
do something l33t on sequences was a Python design mistake.  It
leads to semantics like this:

	x = 10
	y = "10"
	
	x*2
20
	y*2
'1010'
	int(y*2)
1010
	int(y)*2
20

     That's awful.  It's the kind of thing a novice C++
programmer would write shortly after they discovered operator
overloading.

     Now, ask yourself, when you get a numeric value back from
a database, is it an integer or a string?  How about the CSV
module?  Are you sure?

				John Nagle



More information about the Python-list mailing list