[Tutor] why can you swap an immutable tuple?
Jim Mooney
cybervigilante at gmail.com
Sun May 26 05:16:23 CEST 2013
On 25 May 2013 19:38, Steven D'Aprano <steve at pearwood.info> wrote:
> On 26/05/13 05:23, Mark Lawrence wrote:
>
> On the right hand side, 5,8 creates a tuple, which is then immediately
> unpacked to two individual values. You can see this by disassembling the
> code. In 2.7, you get this:
>
> py> from dis import dis
> py> code = compile("a, b = 5, 8", "", "exec")
> py> dis(code)
> 1 0 LOAD_CONST 3 ((5, 8))
> 3 UNPACK_SEQUENCE 2
> 6 STORE_NAME 0 (a)
> 9 STORE_NAME 1 (b)
> 12 LOAD_CONST 2 (None)
> 15 RETURN_VALUE
>
> That disassembling looks like it could clarify a number of things. I'll
have to try it. It might make more sense to me since my only programming,
besides a bit of javascript copy-hacking for websites, was A86 Assembler,
some decades ago, when I wrote an ASCII Art prog for Fidonet.
Then I got into other fields entirely to make a living. But Asm actually
makes sense to me and the disassemble looks close to it. (I can't count the
times I wiped out DOS and had to reload it ;') A86 had a wonderful macro
language, though.
Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130525/bdb7e641/attachment.html>
More information about the Tutor
mailing list