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

  • Home
  • SEARCH
  • 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 8801441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:50:06+00:00 2026-06-14T00:50:06+00:00

why this code is wrong? for i,j in range(100),range(200,300): print i,j when I test

  • 0

why this code is wrong?

for i,j in range(100),range(200,300):
    print i,j

when I test this for statement I see this error

ValueError: too many values to unpack

but when I test

for i, j in range(2),range(2):
     print i,j

every thing is correct!

  • 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-14T00:50:07+00:00Added an answer on June 14, 2026 at 12:50 am

    range(2) gives a list [0, 1]. So, your i, j will be fetched from first list and and then from the second list.

    So, your loop is similar to: –

    for i, j in [0, 1], [0, 1]:
        print i, j
    

    Prints: –

    0 1
    0 1
    

    Now, if you have range(3) there, then it will fail, because, range(3) gives a 3-element list, which cannot be unpacked in two loop variables.

    So, you cannot do: –

    for (i, j) in [[0, 1, 2]]:
        print i, j
    

    It will fail, giving you the error that you are getting.

    Try using zip, to zip your both list into one.: –

    >>> for (i, j) in (zip(range(2), range(3))):
        print i, j
    
    
    0 0
    1 1
    >>> 
    

    zip converts your lists into list of tuples with 2 elements in the above case, as you are zipping 2 lists.

    >>> zip(range(2), range(3))
    [(0, 0), (1, 1)]
    

    Similarly, if you zip three lists, you will get list of 3-elements tuple.

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

Sidebar

Related Questions

Anyone see what is wrong with this code. I'm getting an 'object required' error:
This piece of code was written to generates 100 random numbers between 0 and
What's wrong with this code? I get: TypeError: older is undefined (10 out of
Please can someone really tell me what's wrong with this code that I'm having
Can anyone tell me what I a doing wrong with this code? I am
This code shows correctly as Ecole with an accent on E : NSString *test
This code should be (and is) very simple, and I don't know what I
I have this code for a simple Dice throwing program with betting units and
I'm sorry if this is too simple for some people, but I still don't
I just wrote a simple piece of code to perf test Redis + gevent

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.