Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading