trouble to print array contents using slice operator

Discussion in 'Python' started by praba kar, Apr 16, 2005.

  1. praba kar

    praba kar Guest

    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
    praba kar, Apr 16, 2005
    #1
    1. Advertising

  2. 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
    Diez B. Roggisch, Apr 16, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. keto
    Replies:
    0
    Views:
    927
  2. johughes

    Operator on array slice

    johughes, Nov 27, 2009, in forum: VHDL
    Replies:
    0
    Views:
    583
    johughes
    Nov 27, 2009
  3. Replies:
    3
    Views:
    129
    Dave Weaver
    Sep 8, 2005
  4. Replies:
    9
    Views:
    241
    David Squire
    May 22, 2006
  5. Peng Yu
    Replies:
    4
    Views:
    97
    Tim Greer
    Nov 29, 2008
Loading...

Share This Page