Search code examples
pythonpython-2.7typeerror

Python variable named range hides range() function in terminal


I am using Python 2.7.3 and IPython 0.12.1 and while in terminal I initialized a variable named range. I don't won't to restart the session and I want to use the range function. I tried to set the variable to None, but then I get the following error when I try to call range():

range = [1,2,3]
range = None
range(0,3000,5)

TypeError: 'NoneType' object is not callable


Solution

  • You have to delete range variable to get built-in function back but not give it a none.

    Like this:

    >>> range
    <built-in function range>
    >>> range = 1
    >>> range
    1
    >>> del range
    >>> range
    <built-in function range>