Search code examples
pythonanacondatypeerror

TypeError: 'str' object is not callable for a FOR loop


for abcd in range(3):
    print("d")

is giving me the error TypeError: 'str' object is not callable

Restart Kernal resolves the issue or if I run the code on another ipynb file I am not getting the error. I can reproduce the error multiple times. Any help to fix this without restarting the kernal ??

thanks jaideep


Solution

  • Executing this simply code on my own raises no error and gives the expected output, so I would bet my money you have defined a variable called range somewhere in your code, thus renaming the range keyword. Then, when you call range(3) so get an error because you are not actually calling the python range function, but your own str variable.