Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Stephen Hansen Newsgroups: comp.lang.python Subject: Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask] Date: Sun, 10 Apr 2016 17:18:31 -0700 Lines: 32 Message-ID: References: <1460333911.3449208.574628345.4B46CD32@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de DXreDtA9UUQpaHJXsEaIigDf1eJ8s12EHUKBc0W41dxg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:question': 0.08; 'received:internal': 0.09; 'subject:still': 0.09; 'tuple': 0.09; 'python': 0.10; 'message-id:@webmail.messagingengine.com': 0.16; 'one-element': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:66.111.4.27': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:out3-smtp.messagingengine.com': 0.16; 'received:psf.io': 0.16; 'subject:Was': 0.16; 'tuple,': 0.16; 'wrote:': 0.16; 'element': 0.18; '>>>': 0.20; 'do.': 0.22; 'stephen': 0.22; 'header:In-Reply-To:1': 0.24; 'question': 0.27; 'subject: [': 0.29; 'convert': 0.29; 'guess': 0.31; 'there': 0.36; 'to:addr :python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'no,': 0.38; 'received:66': 0.38; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'behavior': 0.61; 'header:Message-Id:1': 0.61; 'observed': 0.84; 'subject:, \n ': 0.84; 'mistake': 0.91; 'subject:want': 0.93 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=ixokai.io; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=9U/zKVuKyoqtG9efcetR6DToCUc=; b=AE5ubi wKinnHMCputlfHtNMFCt/6S6i94kVr1mm0tOTQzNaWIbqG8/LV1nE75mBFiD1YRA IlCSkdSL5iJs1+l8xFrVy+jNrvxne/zUON7WxHWHkeoAJ9psBIWch7R3Ae+IwQgp zMDFflI3Uk/SvYqU6ulhBQ6fZgwnz/tWLT8pg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=9U/zKVuKyoqtG9e fcetR6DToCUc=; b=PxOZf2mcQPR70fiEMXiDazJsHBKAsz0p/zhyFxzUzHVhnR0 BjUgSN7NDv0znbsJAGGvK3GO1iwr5rry2/XE4aL4+6/qVWyKwdDqqqZ7YkuGFWCG U/yfG94T54wfQqbT9k6FUzdJcJzPkPQeSCBxzh2azQ/0ZY/l/uACL+F1Mj3A= X-Sasl-Enc: G5S1AbW/Dr5AdgSiu4tAvjMvqPlgBjeh2R8c5Sa2cQyY 1460333911 X-Mailer: MessagingEngine.com Webmail Interface - ajax-eadf0bcf 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: <1460333911.3449208.574628345.4B46CD32@webmail.messagingengine.com> X-Mailman-Original-References: Xref: csiph.com comp.lang.python:106806 On Sun, Apr 10, 2016, at 05:13 PM, Fillmore wrote: > 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? No, you didn't. Your mistake is again -- parens don't make tuples, commas do. A one element tuple is: >>> b = ("hello,) The parens are optional, I always put them in because: >>> b = "hello", The parens group an expression, they don't make a type. -- Stephen Hansen m e @ i x o k a i . i o