#Dictionary Loop
d = {'key1':1,'key2':2}
for j in d:
print(j, end=" ")
print(j+" "+ str(d[j]))
Traceback (most recent call last): File "E:/Learning/Python/ComparisonAndControlFlow/ForLoop.py", line 22, in print(j+" "+ str(d[j])) TypeError: 'str' object is not callable*
You assigned the variable name str to something elsewhere in your code, shadowing the str built-in. A minimal reproduction would be:
>>> str = 'something'
>>> try_string = str(5)
TypeError: 'str' object is not callable
Python tries to use your assigned variable for the function call, resulting in your error. Find whatever you named str in your code, and rename it.
In general, always make sure you don't shadow built-ins with your variable names, to prevent this from happening.
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