Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Parens do create a tuple (was: one-element tuples [Was: Most probably a stupid question, but I still want to ask]) Date: Mon, 11 Apr 2016 10:50:36 +1000 Lines: 33 Message-ID: References: <1460333911.3449208.574628345.4B46CD32@webmail.messagingengine.com> <85r3ed2ctn.fsf_-_@benfinney.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de efFMX23yxKJ3GlLWfZB04gUziu4v89SGmaL37vV9hsDA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'works.': 0.07; 'subject:question': 0.08; 'cc:addr:python-list': 0.09; '(1,': 0.09; 'literal': 0.09; 'optional': 0.09; 'subject:create': 0.09; 'subject:still': 0.09; 'surrounded': 0.09; 'tuple': 0.09; 'tuple.': 0.09; 'assume': 0.11; 'syntax': 0.13; 'subject: \n ': 0.15; '10:45': 0.16; '2016': 0.16; 'comma': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'one- element': 0.16; 'progression': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Was': 0.16; 'tuple,': 0.16; 'wrote:': 0.16; 'element': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '(the': 0.22; 'am,': 0.23; 'slightly': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'followed': 0.27; 'message-id:@mail.gmail.com': 0.27; 'subject: [': 0.29; 'code:': 0.29; 'rules': 0.31; 'up.': 0.32; 'problem': 0.33; 'usually': 0.33; 'case,': 0.34; 'correctly': 0.34; 'except': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'basic': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'wanted': 0.37; 'received:209': 0.38; '(1)': 0.38; 'wrong': 0.38; 'someone': 0.38; 'subject:-': 0.39; 'where': 0.40; 'some': 0.40; "you'll": 0.61; 'show': 0.62; 'different': 0.63; "they're": 0.66; 'chrisa': 0.84; 'progression.': 0.84; 'to:none': 0.91; 'subject:want': 0.93; 'examine': 0.95 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=Ou/bbF2h3xg26ouYkh+aDGeyrrJ3x2LE1kjXKfyf4ac=; b=XEe9LMBrZC2sjPjLt5s9Ptlf366S5KpBexQW77KXPPb/EYGbgjbZo7npxvi+aXxxV1 ZhSPUCW6P6Q7JnktiOdjapaHWfpSV/hyWXlEf2vKwStkiscp/TaPQdzmMdFA/pRodPmS uspYkn0za6wZoqAP3JgBBJZygHQje17cDYpo6tmxzxBp1vxgZ8Zv+gGAfZAXGDTmdLxJ si2iQU6OJC0vMnJFXdKpTNLGijBk2P9HRgZV5BK9VawAw7K6jis66yeAxA877Nf62LG2 fMWnPlfkWROtJhCYCYuAiog9FncPFA07XmlSD5OOjNrHOEKgU19UWyBqhs4LPwBE2kol 0bvg== 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=Ou/bbF2h3xg26ouYkh+aDGeyrrJ3x2LE1kjXKfyf4ac=; b=iLjBXcX1YY4GSQ5Gq4OtpK0KPHj8HHmuu4rLrXdc52ptnANSXU+I16qjaVjoaqV1GL d7d/lUUgJWNkGS1V8NloO7GDMCmdOfDD1I1ebvC5cz5JFl3AONH3b/y1Etwl0gMj8wY6 p/4pmB65ig8QL9YJdt+lJWRre8EMN3rmUEw/+HZGFZPk0HgMD0FlDfw3VLMFjdYMG9Dv UlwZAvYkw3wcQ4IVVGUcTUlrkcd4QzFoWPMDSaJQf7jtEphzMZ4cJqQWaL6OarwCtYYZ aGkxs9sBVrB+pkF3kjDqSxJLnXsYcqcL2mFqSZAdW1kqszX2jeaZ09kVxHtc2J832R7P Cvug== X-Gm-Message-State: AD7BkJJagVYOFZCiCipzWBGtgxb3ehBRoS1/3y9XEhctR3qO0LboH5lccVqLuFUoiWTQxIkHnBqhOP1aR5DLQA== X-Received: by 10.50.23.80 with SMTP id k16mr15923905igf.94.1460335836916; Sun, 10 Apr 2016 17:50:36 -0700 (PDT) In-Reply-To: <85r3ed2ctn.fsf_-_@benfinney.id.au> 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: <1460333911.3449208.574628345.4B46CD32@webmail.messagingengine.com> <85r3ed2ctn.fsf_-_@benfinney.id.au> Xref: csiph.com comp.lang.python:106817 On Mon, Apr 11, 2016 at 10:45 AM, Ben Finney wrote: > So the expanation that remains true when you examine it is: People > wanted a literal syntax to create a zero-length tuple. A pair of parens > is that literal syntax, and it's the parens that create the (empty) > tuple. But parens do NOT create a one-element tuple, and that's usually where people trip up. If you show someone this line of code: x = () and ask what x will be, you might get some wrong responses, but you'll get a lot of people correctly deducing that it's a tuple. The problem is that people see this progression: x = () y = (1) z = (1, 2) and assume they're all tuples. A better progression is this: x = () y = (1,) z = (1, 2,) where every element is followed by a comma and every tuple is surrounded by parentheses. In that situation, everything works. There are slightly different rules about which parts are optional (the parens everywhere except the first case, and the last comma everywhere except the second), but this should be the basic form of tuple progression. ChrisA