Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65346

Re: [newbie] troubles with tuples

References <893ced1a-dd55-48d7-8849-b2e45da2740e@googlegroups.com>
Date 2014-02-03 12:00 -0500
Subject Re: [newbie] troubles with tuples
From Larry Martell <larry.martell@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.6345.1391446843.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Feb 3, 2014 at 11:50 AM, Jean Dupont <jeandupont314@gmail.com> wrote:
> I'm looking at the way to address tuples
> e.g.
> tup2 = (1, 2, 3, 4, 5, 6, 7 );
>
> As I found out indices start with 0 in Python, so
> tup2[0] gives me 1, the first element in the tuple as expected
> tup2[1] gives me 2, the second element in the tuple as expected
> now here comes what surprises me:
> tup2[0:1] does not give me the expected (1,2) but (2,)
>
> what is the reason for this and how then should one get the first and the second element of a tuple? Or the 3rd until the 5th?
>
> thanks in advance and kind regards,

Some examples:

a[start:end]  # items start through end-1
a[start:]       # items start through the rest of the array
a[:end]        # items from the beginning through end-1
a[:]             # a copy of the whole array
a[-1]           # last item in the array
a[-2:]          # last two items in the array
a[:-2]          # everything except the last two items

HTH,
-larry

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[newbie] troubles with tuples Jean Dupont <jeandupont314@gmail.com> - 2014-02-03 08:50 -0800
  Re: [newbie] troubles with tuples Asaf Las <roegltd@gmail.com> - 2014-02-03 08:59 -0800
  Re: [newbie] troubles with tuples Larry Martell <larry.martell@gmail.com> - 2014-02-03 12:00 -0500
  Re: [newbie] troubles with tuples Rustom Mody <rustompmody@gmail.com> - 2014-02-03 09:06 -0800
    Re: [newbie] troubles with tuples Jean Dupont <jeandupont314@gmail.com> - 2014-02-03 11:18 -0800
  Re: [newbie] troubles with tuples Terry Reedy <tjreedy@udel.edu> - 2014-02-03 16:52 -0500
  Re: [newbie] troubles with tuples Denis McMahon <denismfmcmahon@gmail.com> - 2014-02-04 00:50 +0000

csiph-web