Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ben Finney Newsgroups: comp.lang.python Subject: 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:45:08 +1000 Lines: 49 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 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de JiHyIpQOJcNtmC9q/Fu5/AqxQMdkkta7HCTNS2NMFJiQ== Cancel-Lock: sha1:MBVnM/y5qjkE6hkQ9Mdy9ZlhIL4= 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; 'mrab': 0.05; 'though:': 0.07; 'subject:question': 0.08; 'literal': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:create': 0.09; 'subject:still': 0.09; 'tuple': 0.09; 'tuple.': 0.09; 'exception': 0.13; 'syntax': 0.13; 'do,': 0.15; 'already,': 0.16; 'comma': 0.16; 'parentheses': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'subject:Was': 0.16; '>>>': 0.20; 'do.': 0.22; 'saying': 0.22; 'stephen': 0.22; 'tuples': 0.22; "i've": 0.25; 'header:User- Agent:1': 0.26; "doesn't": 0.26; 'header:X-Complaints-To:1': 0.26; 'chris': 0.26; 'seed': 0.29; 'subject: [': 0.29; 'another': 0.32; 'foo': 0.33; 'items.': 0.33; 'so,': 0.35; 'false': 0.35; 'stopped': 0.35; 'too': 0.36; 'needed': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'wanted': 0.37; 'skip:o 20': 0.38; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'future': 0.60; 'avoid': 0.61; 'telling': 0.61; 'believe': 0.66; 'obvious': 0.76; 'truth': 0.79; '_o__)': 0.84; 'confusion.': 0.84; 'mandatory.': 0.84; 'mencken': 0.84; 'received:125': 0.84; '\xe2\x80\x94henry': 0.84; 'subject:want': 0.93; 'examine': 0.95 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) 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: <85r3ed2ctn.fsf_-_@benfinney.id.au> X-Mailman-Original-References: <1460333911.3449208.574628345.4B46CD32@webmail.messagingengine.com> Xref: csiph.com comp.lang.python:106815 Stephen Hansen writes: > […] parens don't make tuples, commas do. Chris Angelico writes: > The thing you're confused at is that it's not the parentheses that > create a tuple. Parentheses merely group. MRAB writes: > As has been said already, it's the comma that makes the tuple. The > parentheses are often needed to avoid ambiguity. This is too simplistic, and IMO it's just sowing the seed for future confusion. As MRAB states in the same message: > There _is_ one exception though: (). It's the empty tuple (a 0-element > tuple). It doesn't have a comma and the parentheses are mandatory. > There's no other way to write it. So, let's please stop saying “parens don't create a tuple”. They do, and because of that I've stopped saying that false over-simplification. A pair of tuples as an expression is literal syntax to create a tuple with zero items. Also, there is another obvious way to create an empty tuple: call the ‘tuple’ type directly: >>> foo = tuple() >>> print(type(foo), len(foo)) 0 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. -- \ “It is hard to believe that a man is telling the truth when you | `\ know that you would lie if you were in his place.” —Henry L. | _o__) Mencken | Ben Finney