Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'subject:: [': 0.04; 'element': 0.07; 'indices': 0.07; 'advance': 0.07; '-larry': 0.09; '(1,': 0.16; 'examples:': 0.16; 'surprises': 0.16; 'tuple': 0.16; 'wrote:': 0.18; 'subject:] ': 0.20; 'feb': 0.22; 'to:name:python-list@python.org': 0.22; 'mon,': 0.24; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'rest': 0.29; 'am,': 0.29; 'array': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'gives': 0.31; 'jean': 0.31; 'tuples': 0.31; 'beginning': 0.33; 'subject:with': 0.35; 'except': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'thanks': 0.36; 'should': 0.36; 'two': 0.37; 'expected': 0.38; 'e.g.': 0.38; 'to:addr:python- list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'first': 0.61; 'address': 0.63; 'kind': 0.63; 'here': 0.66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Exd6ykWdHRp9Ckp3h52VTDPDT2ZkE7cOLkyta6wLgtk=; b=J5Les9ok98U47zJDHH32ATWj13Gi5yVySlqrb0EgzfJN2TmUhfmF4yqO55ZQ3sf6CH tmoNauW67AtQgA+ct+rPfe+LSwmLIvrcYpUj8DGyYxTNLDTA6brjWtSD96lyYiO9Ww/o QKIZJx5LGPVQSyN6vQFT6L0/fOaMGeBoxgIER3QupOB2XnMK28YTLxWKNFRt+vxCwJmv jsG8tdbSp+vcXcp2j5YY7Ikxz4WqT6JUr3cMOhccZYlPZaawFTidanIZXJqvspIUlxhG EHUz4jYF/YZGUXcOA/pRGMXtTrePfWhKklcDEzR2uCA/3Fu4FroWtS4PtKPo5QUtfkBO YSag== MIME-Version: 1.0 X-Received: by 10.229.193.136 with SMTP id du8mr24420789qcb.11.1391446833814; Mon, 03 Feb 2014 09:00:33 -0800 (PST) In-Reply-To: <893ced1a-dd55-48d7-8849-b2e45da2740e@googlegroups.com> References: <893ced1a-dd55-48d7-8849-b2e45da2740e@googlegroups.com> Date: Mon, 3 Feb 2014 12:00:33 -0500 Subject: Re: [newbie] troubles with tuples From: Larry Martell To: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391446843 news.xs4all.nl 2880 [2001:888:2000:d::a6]:59914 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65346 On Mon, Feb 3, 2014 at 11:50 AM, Jean Dupont 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