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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:19:08+00:00 2026-06-04T14:19:08+00:00

As mentioned here , you can use the star for unpacking an unknown number

  • 0

As mentioned here, you can use the star for unpacking an unknown number of variables (like in functions), but only in python 3:

>>> a, *b = (1, 2, 3)
>>> b
[2, 3]
>>> a, *b = (1,)
>>> b
[]

In python 2.7, the best I can come up with is (not terrible, but annoying):

c = (1, 2, 3)
a, b = c[0], c[1:] if len(c) > 1 else []

Is there a way to import this from __future__ like division, or will I need my own function to do unknown-length unpacking in 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-04T14:19:10+00:00Added an answer on June 4, 2026 at 2:19 pm

    in python 2.X, you can do:

    c = (1, 2, 3)
    a, b = c[0], c[1:]
    

    as long as c has at least one member it will work because if c only has 1 thing in it c[1:] is [].

    You should probably make sure there is at least one thing in c though, or else c[0] will raise an exception.

    You could do something like:

    try:
        c = tuple(c)
        a, b = c[0], c[1:]
    except TypeError, IndexError:
        # c is not iterable, or c is iterable, but it doesn't have any stuff in it.
        # do something else
        pass
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We would like to use mercurial for web development, but we can't (and don't
I can't see it as mentioned here: http://www.c-sharpcorner.com/uploadfile/mahesh/dll12222005064058am/dll.aspx Do I have to activate somehow
Itest is an Interface. here i mentioned like new Itest(). Then is it means
I was searching arround here and I found that I can use one of
I can use PowerShell to do this fairly easily, but I am looking for
I know that can co-exists with web form no problem as Hanselman mention here
I get the error mentioned here: C++ Templates Error: no matching function for call
As I mentioned here , I'm trying to generate HTML from an ASPX page
I am using git configuration mentioned here If I create a new tab and
I was wondering about the last constructor for std::string mentioned here . It says:

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.