0
for range in ranges:
    print(range)

I have used the above code by mistake overwrote range keyword - Is there any way to retrieve this keyword?

Austin
  • 25,759
  • 4
  • 25
  • 48
A. Erwemi
  • 19
  • 1
  • 2

2 Answers2

1

You can get it from the builtins module:

import builtins
range = builtins.range

Or if you're using Python 2.7 or earlier:

import __builtin__
range = __builtin__.range
blhsing
  • 91,368
  • 6
  • 71
  • 106
  • this works do i need to do this whenver i like to use range – A. Erwemi Sep 29 '18 at 16:11
  • Do this just in case you overwrite a keyword by mistake in a Python shell, but don't do it intentionally in your actual code as it can easily make your code hard to debug and cause confusion. – blhsing Sep 29 '18 at 16:14
0

Issue a

del range

and you'll have your range back.

progmatico
  • 4,714
  • 1
  • 16
  • 27