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 8376427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:25:45+00:00 2026-06-09T15:25:45+00:00

Possible Duplicate: Why do we need tuples in Python (or any immutable data type)?

  • 0

Possible Duplicate:
Why do we need tuples in Python (or any immutable data type)?

I’m learning Python and have background in Ruby. Not ever having tuples, I can’t imagine why I would need them or why Python leans on them so much.

  • 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-09T15:25:47+00:00Added an answer on June 9, 2026 at 3:25 pm

    The coordinates of a square on a chessboard is one example of good use of tuple. I usually use a Python dict, indexed by tuple, to implement a multidimensional array, rather than list-of-lists or the numpy or array modules:

    board = {}
    board[ 3, 6 ] = "black queen"
    board[ 0, 0 ] = "white king"
    

    You can’t use a mutable (like a list) as a dictionary key, so you need a tuple for this.

    Occasionally you find yourself wanting to return multiple values from a function – a boolean to indicate success or failure plus a string describing the failure mode, for instance:

    if trickyOperationSucceeds():
        return True,"Success!"
    return False,"The tricky thing failed!"
    

    This isn’t a pattern to use a lot, but sometimes it gets you out of trouble. You could also use a list here; it’s only by convention that you’d normally use tuple instead.

    When considering how to represent independent values that have to be passed around together, there’s almost a continuum between tuples, dicts, and classes. Consider three ways of representing that compound return:

    (False, "The tricky thing failed!")
    { "status": False, "message": "The tricky thing failed!" }
    ResultObject( status=False, message="The tricky thing failed!" )
    

    If there’s only one place in your code where you’re doing this, the tuple is attractive for its terseness. If you’re using this pattern a lot, and passing these result pairs back and forth between different modules, you might “upgrade” to the dict, where the elements have meaningful keys. If these results become a major part of your software design, you might upgrade them again to being instances of an object class. It’s a balance between formality and ease of use.

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

Sidebar

Related Questions

Possible Duplicate: Distance between geopoints I have some latitudes and longitudes and i need
Possible Duplicate: Exporting an Environment Variable in Ruby I need to set several environment
Possible Duplicate: Event handlers inside a Javascript loop - need a closure? I have
Possible Duplicate: Get column index from label in a data frame I need to
Possible Duplicate: I need a good way to get data from a thread to
Possible Duplicate: Do you ever need to specify javascript: in an onclick? What is
Possible Duplicate: Need to split arrays to sub arrays of specified size in Ruby
Possible Duplicate: Do I need to release xib resources? IBOutlet WeaponStoreViewTableCell *tblCell; I have
Possible Duplicate: Does Java need tuples? Does Java support triples or at least pairs?
Possible Duplicate: Need help in structuring things in XML file have a structure like

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.