One last shot at the Augmented Assignment PEP

Huaiyu Zhu hzhu at users.sourceforge.net
Wed Sep 13 19:47:10 EDT 2000


>> In article <39BFD47F.FBC4528E at holdenweb.com>, Steve Holden
>> <sholden at holdenweb.com> wrote:

>> I'd vote for:
>> 
>>    a +! [33]
>> 
>> to address the readability issue and provide more logical consistency
>> to the syntax used for object modification.

How about using = for assignment and ! for augmentation?

a = b = [];   a += [1]   # a==[1] and b==[]
a = b = [];   a +! [1]   # a==[1]==b

a = b = ();   a += (1,)  # a==(1,) and b==()
a = b = ();   a +! (1,)  # Error, () is immutable.

We could then say 
	big_matrix +! 3 
to save space and
        integer_with_a_really_long_name += 3
to save typing.


Question:  Which of the two sematics is more "natural"?  Answer: both.

# A and B start with having same number of balls
a = b = 3
# A got 2 extra, how many does B have?
a += 2    # b==3!=a

# A and B are two names of the same database
a = b = DataBase()
# A grows by a list of records, what does B hold?
a +! new_records  # b==a

Huaiyu



More information about the Python-list mailing list