On Tue, Aug 28, 2018 at 12:57 PM Guido van Rossum <gu...@python.org> wrote:

> However, a user who doesn't typically think about the actual semantics of
> iterable unpacking and tuple packing might think this would instead mean
> the following:
>
>   a += x
>   b += x
>   c += x
>
> IOW they might think that this is a clever way to increment three
> variables at once:
>
>   a, b, c += 1
>
> This ambiguity (in naive users' minds) leads me to frown upon the proposal.
>

This sort of broadcasting is often quite convenient in Numpy, where many
arithmetic operators will accept scalars or vectors and generally "do the
right thing" in the context. It gets complicated in higher dimensions, but
for 0/1-dimensions you don't need an axis-selector.

    abc = np.array([1, 2, 3])
    abc += 1
    print(abc)
    # [2 3 4]

    abc += [10, 100, 1000]
    print(abc)
    # [  12  103 1004]

The quirks I see are with + being a concatenation operator for lists/tuples.

    a, b = (10, 20)
    # a, b += (1, 2)
    # a, b == 11, 22?
    (a, b) + (1, 2)
    # (10, 20, 1, 2)

Nick
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to