trouble to print array contents using slice operator
Diez B. Roggisch
deetsNOSPAM at web.de
Sat Apr 16 10:50:13 EDT 2005
praba kar wrote:
> Dear all,
>
> In Php array_slice function base
> we can print array contents as per our desire
> eg)
>
> $a = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
> $arr = array_slice($a,10,10);
>
> this function will print 11,12,13,14,15
>
> But I try to print the same thing in python
> using slice operator
>
> eg) print a[10:10]
>
> This statement print [] empty array.
>
> How I need to get my desired output like php
> array_slice function?
Slicing indices in python are [start:stop], not [start:lengh]. So use
print a[10:10+10]
--
Regards,
Diez B. Roggisch
More information about the Python-list
mailing list