Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #27080

Re: it's really strange.how does it work?

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <chris@rebertia.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'variables.': 0.07; 'python': 0.09; '"if': 0.09; '(0,': 0.09; '(1,': 0.09; 'received :mail-vb0-f46.google.com': 0.09; 'snippet': 0.09; 'targets': 0.09; 'terms,': 0.09; 'tuple': 0.09; 'cc:addr:python-list': 0.10; 'aug': 0.13; '2.7.2': 0.16; 'assigned,': 0.16; 'commas,': 0.16; 'iterable': 0.16; 'wrote:': 0.17; 'creates': 0.18; '>>>': 0.18; 'received:209.85.212.46': 0.18; 'respective': 0.20; 'anonymous': 0.22; 'assignment': 0.22; 'tuples': 0.22; 'cheers,': 0.23; 'cc:2**0': 0.23; "python's": 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'url:wiki': 0.26; '(e.g.': 0.27; 'list:': 0.27; 'message- id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'chris': 0.28; 'url:wikipedia': 0.29; 'code': 0.31; 'url:python': 0.32; 'received:google.com': 0.34; 'so,': 0.35; 'pm,': 0.35; 'subject:?': 0.35; 'similar': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'really': 0.36; 'url:org': 0.36; 'does': 0.37; 'being': 0.37; 'item': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'url:en': 0.38; 'list,': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'more': 0.63; 'url:%1': 0.68; 'direct': 0.69; 'sender:addr:chris': 0.84; 'url:reference': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=B9VLIKS7mdPytPfQ9sP9UZzGBCR4LTU57KuO4I1qRYE=; b=KD5wCzTP6D8uPYUoIC84jW0SrIB54Y/hMI8aWL6yCKy87jE9nPLx7zmlK/OeZvGp5y ChqdtFgMUWa0FvP/fZSIMpRNDzNFCXN+iqxTtHEHglq05PTU6THUz99dnU7/blHyAk06 Vw9+if0jw8CY8EndTeCV/pjyobFbm9fhAcuO4=
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=B9VLIKS7mdPytPfQ9sP9UZzGBCR4LTU57KuO4I1qRYE=; b=MREGOy6VQVjL7e7cwYttSJ7Vr4+6UbhD/wfPiBbBrQckb61fe4Qa+T3uGLWk9g+rYf S+uJBU/zMtYnrA2LFg6tC/SfJHbU+T83zSpRvT5uSO2H/oSFZY62Okzsc4r/O+K7tSXt O+OyanGcS4cXDjKzd05EeV8MdgJJhWyvqjOJ6FM6/AlPr7FdtGaaCoKXGnKIYdt/uu1Q 9RTm9k8iKZCaFa7k5Q25FR2GEvgIEizr9PHezNvZrSMPjr4OCi4HQl2go+xoKXvfHycq jr/6LuNvN8i1qkI2pvav5yQTXqq00sx7Rokqb7o+cj661RK8ZMT39oB37l8rCkuxlX7t +hEQ==
MIME-Version 1.0
Sender chris@rebertia.com
In-Reply-To <CAEMsKDuzVPN1_k0n3NpBA=XZ340BLPmReMNozKk7O9-hY8+GEQ@mail.gmail.com>
References <CAEMsKDuzVPN1_k0n3NpBA=XZ340BLPmReMNozKk7O9-hY8+GEQ@mail.gmail.com>
Date Tue, 14 Aug 2012 22:24:04 -0700
X-Google-Sender-Auth cX45VCdwVgfFs9B3PebmA30XbpI
Subject Re: it's really strange.how does it work?
From Chris Rebert <clp2@rebertia.com>
To levi nie <levinie001@gmail.com>
Content-Type text/plain; charset=UTF-8
X-Gm-Message-State ALoCoQm/+LcNMOIcYeHqCibjuEkktz/MkcaM6Bs5f0rIhexzqw56XDWASW5Fmlm65p5U/Gnuoyko
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3301.1345008246.4697.python-list@python.org> (permalink)
Lines 36
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1345008246 news.xs4all.nl 6920 [2001:888:2000:d::a6]:40205
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:27080

Show key headers only | View raw


On Tue, Aug 14, 2012 at 10:07 PM, levi nie <levinie001@gmail.com> wrote:
> ok,what does "start, stop = 0, start" in the code mean?
> it's really strange.how does it work?

It's just parallel assignment
(http://en.wikipedia.org/wiki/Assignment_%28computer_science%29#Parallel_assignment
).

As to exactly how it works:
http://docs.python.org/reference/simple_stmts.html#assignment-statements :
"If the target [of the assignment] is a comma-separated list: The
[value being stored] must be an iterable with the same number of items
as there are targets in the target list, and the items are assigned,
from left to right, to the corresponding targets." [not a completely
direct quote]

Tuples are iterable (e.g. we can write `for item in some_tuple:`; in
laymen's terms, it's similar to being a sequence). Recall that commas,
and not parentheses, are what create tuples according to Python's
syntax:
$ python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 1,2
>>> x
(1, 2)
>>> type(x)
<type 'tuple'>
>>>

So, your code snippet creates an anonymous temporary tuple of length 2
[i.e. (0, start) ], and the assignment then unpacks that tuple into
the 2 respective variables.

Cheers,
Chris

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: it's really strange.how does it work? Chris Rebert <clp2@rebertia.com> - 2012-08-14 22:24 -0700

csiph-web