problem about list indexing

hollowspook hollowspook at gmail.com
Sun Nov 26 05:58:30 EST 2006


Thanks, bearophile.
range(1, 8) + [10] is great!

"bearophileHUGS at lycos.com 写道:
"
> hollowspook:
> > how about indexing 1-7, 10
> > [range(1:8),10] will generate [[1, 2, 3, 4, 5, 6, 7], 10], instead of
> > [1, 2, 3, 4, 5, 6, 7, 10]
>
> (Note that range(1:8) is a syntax error).
>
> You can join and extend lists as you like:
>
> >>> range(1, 8) + [10]
> [1, 2, 3, 4, 5, 6, 7, 10]
>
> See also the list.append and list.extend methods too.
> 
> Bye,
> bearophile




More information about the Python-list mailing list