Python 2.0b1 is released!

Pat Knight nospam at ktgroup.co.uk
Fri Sep 8 09:09:37 EDT 2000


In article <n2khrso0khf70shv1cm6aainnmvolgo89i at 4ax.com>, tdickenson at geminidataloggers.com wrote:
>nospam at ktgroup.co.uk (Pat Knight) wrote:
>
>>Sadly, it now means there's *more than one way to do it* (x += 1 and
>>x = x +1). I understand the two might have slightly different semantics in 
>>some cases?
>
>Which makes only one way to do each. Not so bad ;-)
>

My point was light-hearted, as you realised.

However, in the case of non-mutable objects, there are now two ways to do it.

I'm not looking forward to explaining to my less experienced developers (who 
come from the C/C++ world) why

x= [1,2]
b = x
b += [3]

isn't the same as
x = [1,2]
b = x
b = b + [3]

I know in my heart of hearts that a "+=" operator is a different beast to the 
"+" operator followed by assignment, and "objects can do what they like".
I just get a funny feeling here that the semantics violate expectations, even 
though they don't "break the rules." Even though objects can do what they 
like, very few of us make "+" do a multiplication, simply because we respect 
people's expectations.



More information about the Python-list mailing list