Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Date: Mon, 11 Apr 2016 10:20:32 +1000 Lines: 39 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de MxMpbOvutfiRLPTrnDH9nQjJOK8A+P49LKB2E+SZJ9uw== 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; 'trailing': 0.07; 'subject:question': 0.08; 'cc:addr:python-list': 0.09; 'guys.': 0.09; 'subject:still': 0.09; 'tuple': 0.09; 'tuple.': 0.09; 'python': 0.10; 'subject: \n ': 0.15; '10:13': 0.16; '2016': 0.16; 'comma': 0.16; 'comma,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'one-element': 0.16; 'parentheses': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Was': 0.16; 'tuple,': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'tuples': 0.22; 'trying': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'subject: [': 0.29; 'convert': 0.29; 'guess': 0.31; 'received:google.com': 0.35; 'possible,': 0.35; 'asking': 0.35; 'but': 0.36; 'there': 0.36; 'received:209.85': 0.36; '(and': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'subject:-': 0.39; 'behavior': 0.61; 'legal': 0.66; 'chrisa': 0.84; 'observed': 0.84; 'piss': 0.84; 'to:none': 0.91; 'subject:want': 0.93 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:cc; bh=NK5IuLDKrTHVpoRuKTskHs/EBRZaR7BKQARjuCaWR10=; b=c8jlgbHxZx/hSAp+lsJ+EnaThuQhZPr87qpD1jY4/bnyWE77og74IXxIxUPlS2We7G vBmACo7TwszvtFsX1DdN1AVNsdfIYpVY3TP3uwRDt+tcTR1opdDpzEKWe7ADN1UFpqSu RpldsE9ctvUVCdBdmvog5vBJCU7RNgzfA5nzCbyN8zwHBS9sWZhJT0pcqEzehx1cQm0k 4ZEs6WHXtv/srFTH6ZcDOujBLtOVJjI3Mt4KvZRG5nYIgF4IYFfT9OkPtyzbBWYrgxS9 aZ0baR7kpPmNOkBmzpmj7xBPR5v30wtMzqXhWGtJY8TlblEOgTvShzT13CFg83bacE2k e5yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=NK5IuLDKrTHVpoRuKTskHs/EBRZaR7BKQARjuCaWR10=; b=C799dXKHt3ehV0kaGubJUq4p2MSSZCSRukPjN3Mzqj4ZCr+cQq05DGuip/O2LNfQeO d11EP9A5M177C6eS9qbnktvO40TgRFdJHDa9X+NFbPW35VP/Z0jtF1Faulm1xzSmZkpA ndblh8ICZis9MArFrZ/fZmsLtZOGeic+91+KNacDDkellU/z1Hdud5RzdUwFxQH+QqKL 3IsXucAqxpftMaoK/X9QXmu3nite9PYZbGiINqiH0JpDzsuDKJZmVazeydSQWIDa95Ry juVUAd4levY/FdrdLuL+M7peyWXLQ30+uEvFRRDu7DUxTnixtCtzTEMD91wh3c2sblB8 zfbA== X-Gm-Message-State: AD7BkJLKE1g8rf1tHePzntOisf+3benJEfgAMYx4m04bDsUWmHQk/fG4EY2is3Z+cMwfzJWbKrpDfHVUXWsDrg== X-Received: by 10.50.124.36 with SMTP id mf4mr15509715igb.92.1460334032304; Sun, 10 Apr 2016 17:20:32 -0700 (PDT) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: Xref: csiph.com comp.lang.python:106807 On Mon, Apr 11, 2016 at 10:13 AM, Fillmore wrote: > Sorry guys. It was not my intention to piss off anyone...just trying to > understand how the languare works > > I guess that the answer to my question is: there is no such thing as a > one-element tuple, > and Python will automatically convert a one-element tuple to a string... > hence the > behavior I observed is explained... > >>>> a = ('hello','bonjour') >>>> b = ('hello') >>>> b > 'hello' >>>> a > ('hello', 'bonjour') >>>> > > > Did I get this right this time? Okay, now you're asking a question in a reasonable way, so we can answer :) The thing you're confused at is that it's not the parentheses that create a tuple. Parentheses merely group. >>> 'hello', 'bonjour' ('hello', 'bonjour') >>> 'hello', ('hello',) One-element tuples are perfectly possible, but you MUST have a comma, so you have one at the end. The trailing comma is perfectly legal (and ignored) on larger tuples. >>> 'hello', 'bonjour', ('hello', 'bonjour') ChrisA