Skip to content
  • (+91) 9409548155
  • support@appdividend.com
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Menu
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Python

How to Create List of Numbers with Given Range in Python

  • 26 Nov, 2025
  • Com 0
How to Create a List of Numbers with Given Range in Python

You need to create a list of numbers within a given range to iterate over sequences, simulate data series, initialize arrays for algorithms, or prepare inputs for numerical computations.

The range has a starting point, and the end point is the point before the endpoint.

Method 1: Using range() + list()

Using range() + list() to create a list of given range in Python

To efficiently create an integer-based list within a given range, use the range() function with the start, endpoint, and step arguments. It will return a range object and then convert it to a list using the list() function.

nums = list(range(1, 10, 2))

print(nums)

# Output: [1, 3, 5, 7, 9]

It is the most common way to create a list of sequences.

Method 2: Using List Comprehension

Using List Comprehension to create a list of given range

If you want to create a list with a custom sequence, like a sequence that requires custom logic, you can always go for a list comprehension. It can generate a sequence with conditions or formulas.

nums = [x * 2 for x in range(2, 8)]

print(nums)

# Output: [4, 6, 8, 10, 12, 14]

The output is a new list with computations.

Method 3: Using numpy.arange()

What if you are working with numpy arrays and you want to create a sequence for an AI or ML modeling? That’s where the np.arange() function comes into play.

It generates an array of evenly spaced values over a specified range.

import numpy as np

nums = np.arange(1, 5, 0.5)

print(nums.tolist())

# Output: [1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5]

That’s all!

Post Views: 4
Share on:
Krunal Lathiya

With a career spanning over eight years in the field of Computer Science, Krunal’s expertise is rooted in a solid foundation of hands-on experience, complemented by a continuous pursuit of knowledge.

How to Print All Common Elements of Two Lists in Python
How to Move File or Folder in Python

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Address: TwinStar, South Block – 1202, 150 Ft Ring Road, Nr. Nana Mauva Circle, Rajkot(360005), Gujarat, India

Call: (+91) 9409548155

Email: support@appdividend.com

Online Platform

  • Pricing
  • Instructors
  • FAQ
  • Refund Policy
  • Support

Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of services

Tutorials

  • Angular
  • React
  • Python
  • Laravel
  • Javascript
Copyright @2024 AppDividend. All Rights Reserved
Appdividend