Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: it's really strange.how does it work?

Reply
Thread Tools

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

 
 
Chris Rebert
Guest
Posts: n/a
 
      08-15-2012
On Tue, Aug 14, 2012 at 10:07 PM, levi nie <> 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/Assignm...lel_assignment
).

As to exactly how it works:
http://docs.python.org/reference/sim...ent-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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does printer ink really cost more to make than it does to mine silver? RichA Digital Photography 57 01-18-2012 11:34 PM
OT : But help really really needed re: Domain Name selling, hosting etc. problem nc HTML 1 02-03-2005 07:24 PM
REALLY REALLY WERID PROBLEM!!!!pls take a look Amir ASP .Net 3 01-23-2004 06:01 PM
really really mysterious IE6 problem--secure site ultraviolet353 Computer Support 7 11-22-2003 07:56 PM
MR. ED REALLY, REALLY LOVES THE D60 !!! Annika1980 Digital Photography 9 10-28-2003 04:53 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57