Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8558049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:43:06+00:00 2026-06-11T15:43:06+00:00

Why is there this difference accessing the element(s) of t when making it a

  • 0

Why is there this difference accessing the element(s) of t when making it a tuple?

>>> t = [('ID','int')]
>>> for r in t:
print r


('ID', 'int')


t = (('ID','int'))
>>> for r in t:
print r


ID
int

I’d expect this to be exactly the same as the first example! Whereas populating the tuple with more than one element the behavior changes.

>>> t = (('ID','int'),('DEF','str'))
>>> for r in t:
print r


('ID', 'int')
('DEF', 'str')
>>> t = [('ID','int'),('DEF','str')]
>>> for r in t:
print r


('ID', 'int')
('DEF', 'str')

Can somebody give a short explanation? I’m running python 2.7

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:43:08+00:00Added an answer on June 11, 2026 at 3:43 pm

    (('a', 'b')) is the same as ('a', 'b').

    You actually want (('a', 'b'),)

    This is documented here:

    5.13. Expression lists

    expression_list ::= expression ( "," expression )* [","]

    An expression list containing at least one comma yields a tuple. The length of the tuple is the number of expressions in the list. The expressions are evaluated from left to right.

    The trailing comma is required only to create a single tuple (a.k.a. a singleton); it is optional in all other cases. A single expression without a trailing comma doesn’t create a tuple, but rather yields the value of that expression. (To create an empty tuple, use an empty pair of parentheses: ().)

    Remember, that without this restriction, should the expression (3) * (4) be the multiplication of two numbers, or two tuples? Most users would expect that to be the multiplication of numbers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there anyway this code can be refactored? The only difference is the order
Is there a difference between this.form and document.forms (document[forms]) or, are they similar? Here
Is there any essential difference between this code: ThreadStart starter = new ThreadStart(SomeMethod); starter.Invoke();
Is there any difference between doing this: $(.topHorzNavLink).click(function() { var theHoverContainer = $(#hoverContainer); var
Is there a difference between the following selectors: var index = $(this).parent().index(); var index2
Is there a difference between these two scenarios: (1) Accessing a property on a
When accessing values from an SqlDataReader is there a performance difference between these two:
What's the difference between these: This one works: char* pEmpty = new char; *pEmpty
Is this fine or is there a different way? <a href=Http://<%=Html.Encode(Model.Website)%>><%=Html.Encode(Model.Website??)%></a>
I know that there are many different questions about this sort of topic on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.