Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(2,)!=(2) and (2,3)==(2,3,) why ??? tested in each version #69089

Closed
shivaprasanth mannequin opened this issue Aug 20, 2015 · 2 comments
Closed

(2,)!=(2) and (2,3)==(2,3,) why ??? tested in each version #69089

shivaprasanth mannequin opened this issue Aug 20, 2015 · 2 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@shivaprasanth
Copy link
Mannequin

shivaprasanth mannequin commented Aug 20, 2015

BPO 24901
Nosy @eryksun

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2015-08-20.11:03:15.981>
created_at = <Date 2015-08-20.10:42:08.971>
labels = ['type-bug', 'invalid']
title = '(2,)!=(2) and (2,3)==(2,3,) why ??? tested in each version'
updated_at = <Date 2015-08-20.11:03:15.948>
user = 'https://bugs.python.org/shivaprasanth'

bugs.python.org fields:

activity = <Date 2015-08-20.11:03:15.948>
actor = 'eryksun'
assignee = 'none'
closed = True
closed_date = <Date 2015-08-20.11:03:15.981>
closer = 'eryksun'
components = []
creation = <Date 2015-08-20.10:42:08.971>
creator = 'shivaprasanth'
dependencies = []
files = []
hgrepos = []
issue_num = 24901
keywords = []
message_count = 2.0
messages = ['248880', '248881']
nosy_count = 1.0
nosy_names = ['eryksun']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue24901'
versions = ['Python 2.7', 'Python 3.2', 'Python 3.3', 'Python 3.4']

@shivaprasanth
Copy link
Mannequin Author

shivaprasanth mannequin commented Aug 20, 2015

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
>>>

@shivaprasanth shivaprasanth mannequin changed the title single element tuple 's ending comma is different that without comma (2,)!=(2) and (2,3)==(2,3,) why ??? tested in each version Aug 20, 2015
@shivaprasanth shivaprasanth mannequin added the type-bug An unexpected behavior, bug, or error label Aug 20, 2015
@eryksun
Copy link
Contributor

eryksun commented Aug 20, 2015

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.

@eryksun eryksun closed this as completed Aug 20, 2015
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant