Wednesday, September 17, 2025
HomeLanguagesrangev2 – A new version of Python range class

rangev2 – A new version of Python range class

range() is a built-in function of Python. It is used when a user needs to perform an action for a specific number of times. The range() function is used to generate a sequence of numbers. But the sequence of numbers produced by range is generally either decreasing or increasing linearly which means it is either incremented and decremented by a particular constant.

rangev2 module provides a function new_range() which allows to produce sequence also by using *, //, % operators so that sequence can be varied exponentially is well.

This module does not come built-in with python, so it can be installed by typing the below command in the terminal.

pip install rangev2

Syntax: new_range(start, stop, step)

Parameters:
start – integer starting from which the sequence of integers is to be returned.
stop – integer before which the sequence of integers is to be returned.
step – string containing operand and operator.

Example #1:




# Python Program to  
# show rangev2 basics
  
  
#Importing module
import rangev2 as r2
  
# program to produce Geometeric progression using rangev2
for i in r2.new_range(2, 100, '*2'):
    print(i, end=" ")
print()
  
# printing powers
for i in r2.new_range(2, 1000, '**2'):
    print(i, end=" ")
print()
  
# printing divisions
for i in r2.new_range(100,1,'//3'):
    print(i, end=" ")


Output:

2 4 8 16 32 64
2 4 16 256
100 33 11 3

 
Example #2:




# Python program to produce Geometric progression using rangev2
  
import rangev2 as r2
  
a = '2'    # First number of the geometeric progression
c = '100'  # Enter the upper bond
b = '2'    # Enter the common ration
  
print(r2.new_range(int(a),int(c),'*' + b).list)


Output:

[2,4,8,16,32,64]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32299 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6660 POSTS0 COMMENTS
Nicole Veronica
11833 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11895 POSTS0 COMMENTS
Shaida Kate Naidoo
6779 POSTS0 COMMENTS
Ted Musemwa
7050 POSTS0 COMMENTS
Thapelo Manthata
6735 POSTS0 COMMENTS
Umr Jansen
6741 POSTS0 COMMENTS