The root cause for typeerror str object is not callable error is declaring any variable with “str” name. Actually, if you declare any variable by str name and later on you use str(param) for typecasting. It will point to str variable reference in place of python str object and function. Well, We all know that we can not use any python reserve keyword. As “str” is a reserved keyword in python. Hence we should avoid it.
Typeerror str object is not callable : Real Example-
The above error is quite straight but It will be more interesting to understand with some examples.
Case 1: Declaring variable name as “str”
str="Its an example"
Here is the output for the above code.
You may easily fix this error by changing the variable name. We may choose any variable as per PEP-8 coding standard.
Here is the correct version of the above code.
str_var="It an example"
Case 2: String Formatting % character missing-
There is a very interesting scenario. When we want to use any variable value in a print statement with some text. Let’s see the below example.
print("Most valuable part of decision making is %s"(var))
As we can see in the above example that we have not used “%” character after “. If we apply and re-run it. I am sure that we can fix the above error.
Actually, there can be many scenarios where we get this error Typeerror str object is not callable like in selenium, pandas, matplotlib, djano, etc. But the reason behind this will be always the same. You may fix it with the above tricks.
I hope this article must have solved the issue. know you many Well, If you have any comments on this topic, please write back to us.
Data Science Learner Team
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.