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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:48:04+00:00 2026-05-23T03:48:04+00:00

I am studying the Learn Python The Hard Way PDF. On page 82 i

  • 0

I am studying the Learn Python The Hard Way PDF. On page 82 i come across this question.

  • Could you have avoided that for-loop entirely on line 23 and just assigned range(0,6) directly to elements?

Given the code:

# we can also build lists, first start with an empty one
elements = []

# then use the range function to do 0 to 20 counts
for i in range(0, 6):
    print "Adding %d to the list." % i    # line 23
    # append is a function that lists understand
    elements.append(i)

# now we can print them out too
for i in elements:
    print "Element was: %d" % i

It seems this is not possible unless i use the map function? Am i 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-05-23T03:48:04+00:00Added an answer on May 23, 2026 at 3:48 am

    In python 2.x, range returns a list. In 3.x, it returns an iterable range object. You can always use list(range(...)) to get a list.

    However, for x in y does not require y to be a list, just an iterable (such as xrange(2.x only), range, list, str, …)

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

Sidebar

Related Questions

In studying actionscript 3's graphics class, I've come across the undocumented drawRoundRectComplex() method. It's
I am trying to learn how to use threads with python. this is the
I am trying to teach myself Python, and I have realized that the only
I know that there have been plenty of topics describing this topic but I
I know this may seem like a common question on SO but I could
while studying some security things, there was a question that one can guess the
I was studying method overriding in Java when ai came across the this keyword.
While studying about JMX, I have seen one of the important feature of it
I've been studying the Google authentication API (AuthSub)... My question is, how do I
If one wants to learn better programming practices by studying a small .NET OSS

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.