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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:12:20+00:00 2026-06-15T20:12:20+00:00

Create a list of integers from from a (inclusive) to b (inclusive). Example: integers(2,5)

  • 0

Create a list of integers from from a (inclusive) to b (inclusive).
Example:
integers(2,5) returns [2, 3, 4, 5].

I know this is probably an easy one, but I just can’t seem to get anything to work.

  • 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-15T20:12:21+00:00Added an answer on June 15, 2026 at 8:12 pm
    >>> def integers(a, b):
             return list(range(a, b+1))
    >>> integers(2, 5)
    [2, 3, 4, 5]
    

    To explain your own solution:

    can you explain to me why in some programs you have to include [i] and some it is just i

    def integers(a,b):
       list = []
       for i in range(a, b+1):
           list = list + [i]
    

    i refers to the number itself; [i] is a list with one element, i. When using the + operator for lists, Python can concat two lists, so [1, 2] + [3, 4] is [1, 2, 3, 4]. It is however not possible to just add a single element (or number in this case) to an existing list. Trying so will result in a TypeError.

    What you could do instead of concatenating with a one-element list, is simply append the element by using the method with the same name:

    list.append(i)
    

    One final note, you should not name your variable list (or dict or str etc) as that will locally overwrite the references to the built-in functions/types.

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

Sidebar

Related Questions

With a list of integers such as: [1;2;3;4;5;6;7;8;9] How can I create a list
I have a nested list, like this one for example: test = [[15, [7,
I'd like to create a C# List of integers, from say 1930 to 2010.
I want to create a list of integers from 1 to n . I
How do I find the duplicates in a list of integers and create another
I have this problem : Create a program which constructs a lattice of one
I'd like to create a list maxValues containing top 20 values from a list
The .NET 1.0 way of creating collection of integers (for example) was: ArrayList list
I need to create a string of hex digits from a list of random
I have a list of integers (from 0 to N) and I need to

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.