pic

Try to simplfy the my question here, so used a,b, & c instead.
Even though I copied the tutorial's answer and run it through Colaboratoy, it still show TypeError:'str' object is not callable.
Why is that?
Thank you.
you might somewhere have declared the print as a variable. eg: print = "sample". So restart the session or execute del print command and try executing your code.
del print
a=1
b=2
c=a+b
print(c)
Try executing the above code, also follow the below rules while naming a variable in python.
Here are some examples of valid and invalid identifier names in Python:
# Valid identifier names
_private
_private123
myVariable
myVariable123
MY_CONSTANT
# Invalid identifier names
123invalid # cannot start with a digit
for # for is a reserved word
Answering the question title:
How to fix TypeError: 'str' object is not callable?
As a starter in python I feel the need to answer this because nor python nor editors (at least vscode with python plugin) seem to give a hint that you may have accidentally shadowed a methodName with a fieldName.
Consider the following:
# value field shadows value() method
class ValueWrapper:
def __init__(self):
self.value = 'someValue'
def value(self):
return self.value
print("value:", ValueWrapper().value())
output: TypeError: 'str' object is not callable
# value field does not shadow getValue() method
class ValueWrapper:
def __init__(self):
self.value = 'someValue'
def getValue(self):
return self.value
print("value:", ValueWrapper().getValue())
Output: value: someValue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With