Python 3 added a new range class to efficiently handle "an immutable sequence of numbers" (similar to Python 2's xrange). Python 2 does not have such a range class, so the range function just returns a list.

Answer from Mureinik on Stack Overflow
🌐
W3Schools
w3schools.com › python › ref_func_range.asp
Python range() Function
Python Examples Python Compiler ... ... The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and stops before a specified number....
🌐
Real Python
realpython.com › python-range
Python range(): Represent Numerical Ranges – Real Python
November 24, 2024 - When you call range(), you’re calling the constructor of the range class to create a new range object. Still, for all practical purposes, you can treat range() as a function that returns a range object. First, note that a range is a lazy sequence. This means that Python doesn’t create the individual elements of a range when you create the range.
🌐
Stanford CS
cs.stanford.edu › people › nick › py › python-range.html
Python range() Function
The python range(n) function creates ... likes strings and lists. The range() function can be called in a few different ways shown below (the range feature is implemented as a class......
🌐
Pythontic
pythontic.com › containers › range › introduction
The range class in Python | Pythontic.com
The range class represents an immutable sequence of integers. Range does not support floating point numbers. Range can create integer sequences in positive, negative and in both directions. To produce a sequence of floating point numbers the numpy.arange() can be used.
🌐
Dataquest
dataquest.io › blog › python-range-tutorial
Python Range Tutorial: Learn to Use This Helpful Built-In Function
April 9, 2023 - Notice that range is a type in Python. The default print method of the class prints the range of numbers that the range object will iterate through. Note that the numbers are still not generated — this is due to the memory saving "lazy evaluation" mentioned earlier.
Find elsewhere
🌐
docs.python.org
docs.python.org › 3 › library › functions.html
Built-in Functions — Python 3.14.4 documentation
Note that classes are callable ... if their class has a __call__() method. Added in version 3.2: This function was first removed in Python 3.0 and then brought back in Python 3.2. ... Return the string representing a character with the specified Unicode code point. For example, chr(97) returns the string 'a', while chr(8364) returns the string '€'. This is the inverse of ord(). The valid range for the argument ...
🌐
W3Schools
w3schools.com › python › python_range.asp
Python range
Python Examples Python Compiler ... Training ... The built-in range() function returns an immutable sequence of numbers, commonly used for looping a specific number of times....
🌐
PYnative
pynative.com › home › python › python range() explained with examples
Python range() Function Explained with Examples
March 17, 2022 - The range() by default starts at 0, not 1, if the start argument is not specified. For example, range(5) will return 0, 1, 2, 3, 4. ... The range() function returns an object of class range, which is nothing but a series of integer numbers.
🌐
AskPython
askpython.com › home › understanding the built-in python range() function
Understanding the built-in Python range() function - AskPython
January 25, 2026 - The range() function generates a sequence of numbers that you can iterate over. That’s it. Three parameters, one simple job. You give it boundaries, and it gives you integers within those boundaries.
🌐
Towards Data Science
towardsdatascience.com › home › latest › python range() built-in-function
Python range() built-in-function | Towards Data Science
January 17, 2025 - Yes, the range function is a class because when you check the type of the range function using type() then you get the answer.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-range-function
Python range() function - GeeksforGeeks
The range() function in Python is used to generate a sequence of integers within a specified range.
Published   March 10, 2026
🌐
Python documentation
docs.python.org › 3 › library › stdtypes.html
Built-in Types — Python 3.14.4 documentation
The arguments to the range constructor must be integers (either built-in int or any object that implements the __index__() special method). If the step argument is omitted, it defaults to 1. If the start argument is omitted, it defaults to 0.
🌐
GitHub
github.com › xbmc › python › blob › master › Demo › classes › Range.py
python/Demo/classes/Range.py at master · xbmc/python
"""Function to implement 'range' as a generator""" start, stop, step = handleargs(a) value = start · while value < stop: yield value · value += step · · class oldrange: """Class implementing a range object. To the user the instances feel like immutable sequences ·
Author   xbmc
🌐
Python Land
python.land › home › language deep dives › python range() function: how-to tutorial with examples
Python range() Function: How-To Tutorial With Examples • Python Land
June 27, 2023 - # With one integer argument it ... (python) The arguments start, stop, and step are always integers. When we call range, it returns an object of class range....
Top answer
1 of 2
4

In general it is much easier to answer questions if you provide a specific error message or thing that is going wrong. Here's what happened when I tried to run the above:

  • First up:

    `SyntaxError: invalid syntax` 
    

    on if seq == POSITIVE. What's wrong here? Oh yes, you're missing a colon after the conditional. If you add that the file at least parses. So let's try doing some coding:

    # Your code here, then:
    feature = DNAFeature()
    
  • Running that gives:

    TypeError: __init__() takes exactly 3 positional arguments (1 given)
    

    Oh, OK, we need to pass some arguments to the initialiser of DNAFeature. Let's put this on the + strand, and call it foo:

    feature = DNAFeature(1, "foo")
    
  • Now we get:

    AttributeError: 'DNAFeature' object has no attribute 'setStrand'
    

    What's that about? OK, you haven't defined setStrand. (Note: you shouldn't have to. But more on that later.) Let's define it:

    def setStrand(self, strand):
        self.strand = strand
    

I don't want to go through the rest of the problems with the code (hint: you need to define variables before you use them), but this is the sort of thing you should be doing.


Right, something different. The above is bad code. I hope you've written the Range class and that it hasn't been provided as part of the course, because if it has you're taking a badly-taught course. The main problem is the use of getters and setters -- I'm guessing you're Java-born and bred? In Python you don't need to write getters and setters for everything, because you can always add them in later if you need them. Instead, just use class attributes. Look at the following code for Range:

class Range:
    def __init__(self, start, end):
        self.start = start
        self.end = end

    def length(self):
        return self.end - self.start

    def overlaps(self, other):
        return not(self.end < other.start or other.end < self.start)

Isn't that much nicer? No more nasty accessors, no icky comparisons in the overlaps method... It helps if you work out the logic that your code is trying to implement before you implement it.

See if you can write a better DNAFeature now.


You still haven't told me what getStrand should, do, but here's what I think you're aiming towards. Suppose the strand name that gets passed to __init__ is of the form "+name" or "-name". You can then do the following:

def __init__(self, strand):
    sequence = strand[0] #first character of strand

    if sequence == "+":
        self.strand = 1
        self.sequence= strand[1:]
    elif sequence == "-":
        self.strand = -1
        self.sequence = strand[1:]
    else:
        self.strand = 0
        self.sequence = strand

See if you can work out how that works.

2 of 2
0

In the most generic case (without making any assumptions), it seems that this is what you need:

class DNAFeature(Range):

    def __init__(self, start, end):
        self.setStart(start)
        self.setEnd(end)
        self.strand = None
        self.sequencename = None

    def setStrand(self, s):
        self.strand = s

    def getStrand(self):
        if self.sequenceName == 'plus':
            return 1
        elif self.sequenceName == 'minus':
            return -1
        else:
            return 0

    def setSequenceName(self, s):
        self.sequencename = s

    def getSequenceName(self, s):
        return self.sequenceName

You will notice that here, I have redefined init. There is a reason for this. I remember that in one of your earlier questions, you had mentioned that this was a Java assignment, just renamed to python. In Java, constructors are not inherited (correct me if I'm wrong). Therefore, if the same grading rubric is being used, you will lose marks for not redefining the constructor here.

Hope this helps

🌐
Software Testing Help
softwaretestinghelp.com › home › python › python range function – how to use python range()
Python Range function - How to Use Python Range()
April 1, 2025 - range() is a built-in Python class while numpy.arange() is a function that belongs to the Numpy library.
🌐
Python Examples
pythonexamples.org › python-ranges
Python Ranges
In this tutorial, you will learn about Ranges in Python. The properties, methods, two constructors of range class. How to create a range, print a range, iterate over a range, and operations on a range, with example programs.
🌐
DataCamp
datacamp.com › tutorial › python-range-function
Python Range() Function Tutorial | DataCamp
September 16, 2024 - Let's start with a simple example of printing a sequence of ten numbers, which will cover your first range() parameter. To achieve this, you will be just passing in the stop value. Since Python works on zero-based indexing, hence, the sequence will start with zero and stop at the specified number, i.e., n-1, where n is the specified number in the range() function.