a,b = 2,3 and [a,b] = [2,3]
Alan Bawden
alan at csail.mit.edu
Sun Sep 1 22:33:27 EDT 2019
Eko palypse <ekopalypse at gmail.com> writes:
> Am Montag, 2. September 2019 00:49:05 UTC+2 schrieb Hongyi Zhao:
> > Hi,
> >
> > What's differences:
> >
> > a,b = 2,3 and [a,b] = [2,3]
> >
> > Regards
>
> In this example the result is the same but the second one
> builds, internally, an additional list, therefore isn't as sufficient
> as the first one.
It looks to me like they generate identical code. The first one calls the
construction of a tuple, where the second one calls for the construction of
a list. It would be surprising if the compiler optimized the tuple
away, but failed to optimize the list away!
--
Alan Bawden
More information about the Python-list
mailing list