trouble to print array contents using slice operator

P

praba kar

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?

with regards
Prabahar





________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
 
D

Diez B. Roggisch

praba said:
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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top