anonymous assignment

Kam-Hung Soh kamhung.soh at gmail.com
Tue May 13 01:08:04 EDT 2008


On Tue, 13 May 2008 13:23:30 +1000, Yves Dorfsman <yves at zioup.com> wrote:

> Scott David Daniels wrote:
>> Yves Dorfsman wrote:
>>> ... Sorry this was a typo (again :-), I meant:
>>> d = time.local()
>>>   y = d[0]
>>>   d = d[2]
>> Then:
>>     y, d = list(time.localtime())[:4:2]
>>
>
> What is this ?
> Could you point me to a document on this syntax ?
>
> I've tried it, it works, but I don't understand how.
>
>
> Thanks.
>
> Yves.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

See:

"Built-in Functions", "slice()",  
http://docs.python.org/lib/built-in-funcs.html

l = range(10)
l
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
l[:4]   # first four elements
[0, 1, 2, 3]
l[::2]  # every second element
[0, 2, 4, 6, 8]
l[:4:2] # every second element in the first four elements
[0, 2]

-- 
Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software Salariman</a>




More information about the Python-list mailing list