Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'subject:: [': 0.04; 'element': 0.07; 'indices': 0.07; 'advance': 0.07; 'already.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'jan': 0.12; '(1,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'surprises': 0.16; 'tuple': 0.16; 'wrote:': 0.18; 'subject:] ': 0.20; 'header :User-Agent:1': 0.23; 'second': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "i'm": 0.30; 'gives': 0.31; 'jean': 0.31; 'tuples': 0.31; 'covered': 0.32; 'subject:with': 0.35; 'but': 0.35; 'thanks': 0.36; 'should': 0.36; 'expected': 0.38; 'e.g.': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'read': 0.60; 'received:173': 0.61; 'first': 0.61; 'address': 0.63; 'kind': 0.63; 'here': 0.66; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: [newbie] troubles with tuples Date: Mon, 03 Feb 2014 16:52:18 -0500 References: <893ced1a-dd55-48d7-8849-b2e45da2740e@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-254-207.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: <893ced1a-dd55-48d7-8849-b2e45da2740e@googlegroups.com> 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: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391464507 news.xs4all.nl 2831 [2001:888:2000:d::a6]:52703 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65380 On 2/3/2014 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, This should be covered in the tutorial, which you should read if you have not already. -- Terry Jan Reedy