This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: (2,)!=(2) and (2,3)==(2,3,) why ??? tested in each version
Type: behavior Stage: resolved
Components: Versions: Python 3.2, Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eryksun
Priority: normal Keywords:

Created on 2015-08-20 10:42 by shivaprasanth, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg248880 - (view) Author: shiva prasanth (shivaprasanth) * Date: 2015-08-20 10:42
Python 2.7.9 (default, Apr  2 2015, 15:33:21) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> (2,)==(2)
False
>>> (2,3,)==(2,3)
True
>>> (2,3)==(2,3,)
True
>>> s=(2,)
>>> s2=(2)
>>> s==s2
False
>>>
msg248881 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2015-08-20 11:03
Refer to section 6.2.3, parenthesized forms:

https://docs.python.org/3/reference/expressions.html#parenthesized-forms

    if the list contains at least one comma, it yields a tuple;
    otherwise, it yields the single expression that makes up the
    expression list.

So (2) is an int, while (2,) is a tuple that contains an int.

    The exception is the empty tuple, for which parentheses are
    required — allowing unparenthesized “nothing” in 
    expressions would cause ambiguities and allow common typos
    to pass uncaught.

Thus () is an empty tuple. Note also that section 6.13 states the following regarding a trailing comma:

    The trailing comma is required only to create a single 
    tuple (a.k.a. a singleton); it is optional in all other 
    cases.
History
Date User Action Args
2022-04-11 14:58:19adminsetgithub: 69089
2015-08-20 11:03:15eryksunsetstatus: open -> closed

nosy: + eryksun
messages: + msg248881

resolution: not a bug
stage: resolved
2015-08-20 10:47:00shivaprasanthsetnosy: - shivaprasanth
versions: + Python 3.4
-> (no value)
type: behavior
title: single element tuple 's ending comma is different that without comma -> (2,)!=(2) and (2,3)==(2,3,) why ??? tested in each version
2015-08-20 10:42:08shivaprasanthcreate