By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,594 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,594 IT Pros & Developers. It's quick & easy.

trouble to print array contents using slice operator

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.