OpenQuizz
Une application de gestion des contenus pédagogiques
numeric_range Class Reference
Inheritance diagram for numeric_range:
Collaboration diagram for numeric_range:

Public Member Functions

def __init__ (self, *args)
 
def __bool__ (self)
 
def __contains__ (self, elem)
 
def __eq__ (self, other)
 
def __getitem__ (self, key)
 
def __hash__ (self)
 
def __iter__ (self)
 
def __len__ (self)
 
def __reduce__ (self)
 
def __repr__ (self)
 
def __reversed__ (self)
 
def count (self, value)
 
def index (self, value)
 

Detailed Description

An extension of the built-in ``range()`` function whose arguments can
be any orderable numeric type.

With only *stop* specified, *start* defaults to ``0`` and *step*
defaults to ``1``. The output items will match the type of *stop*:

    >>> list(numeric_range(3.5))
    [0.0, 1.0, 2.0, 3.0]

With only *start* and *stop* specified, *step* defaults to ``1``. The
output items will match the type of *start*:

    >>> from decimal import Decimal
    >>> start = Decimal('2.1')
    >>> stop = Decimal('5.1')
    >>> list(numeric_range(start, stop))
    [Decimal('2.1'), Decimal('3.1'), Decimal('4.1')]

With *start*, *stop*, and *step*  specified the output items will match
the type of ``start + step``:

    >>> from fractions import Fraction
    >>> start = Fraction(1, 2)  # Start at 1/2
    >>> stop = Fraction(5, 2)  # End at 5/2
    >>> step = Fraction(1, 2)  # Count by 1/2
    >>> list(numeric_range(start, stop, step))
    [Fraction(1, 2), Fraction(1, 1), Fraction(3, 2), Fraction(2, 1)]

If *step* is zero, ``ValueError`` is raised. Negative steps are supported:

    >>> list(numeric_range(3, -1, -1.0))
    [3.0, 2.0, 1.0, 0.0]

Be aware of the limitations of floating point numbers; the representation
of the yielded numbers may be surprising.

``datetime.datetime`` objects can be used for *start* and *stop*, if *step*
is a ``datetime.timedelta`` object:

    >>> import datetime
    >>> start = datetime.datetime(2019, 1, 1)
    >>> stop = datetime.datetime(2019, 1, 3)
    >>> step = datetime.timedelta(days=1)
    >>> items = iter(numeric_range(start, stop, step))
    >>> next(items)
    datetime.datetime(2019, 1, 1, 0, 0)
    >>> next(items)
    datetime.datetime(2019, 1, 2, 0, 0)

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
args 
)

Member Function Documentation

◆ __bool__()

def __bool__ (   self)

◆ __contains__()

def __contains__ (   self,
  elem 
)

◆ __eq__()

def __eq__ (   self,
  other 
)

◆ __getitem__()

def __getitem__ (   self,
  key 
)

◆ __hash__()

def __hash__ (   self)

◆ __iter__()

def __iter__ (   self)

◆ __len__()

def __len__ (   self)

◆ __reduce__()

def __reduce__ (   self)

◆ __repr__()

def __repr__ (   self)

◆ __reversed__()

def __reversed__ (   self)

◆ count()

def count (   self,
  value 
)

◆ index()

def index (   self,
  value 
)

The documentation for this class was generated from the following file: