Reputation: 1
I'm working through "Python 101" by Mathew Driscoll and have ran into an issue when I try this.
>>> print("%(lang)s is fun!" % {"lang":"python"})
I understand i'm trying to use the Python dictionary here with lang being a "key value pair" All i'm doing is copying whats in the book but, the book has been out awhile and I'm using the newest version of Python.
This is the error I get:
Traceback (most recent call last):
File "<pyshell#78>", line 1, in <module>
print("%(lang)s is fun!" % {"lang":"python"})
TypeError: 'str' object is not callable
Upvotes: 0
Views: 29
Reputation: 155363
You named a variable print
. Don't do that (in general, never name a variable with the same name as a Python built-in, so no variables named str
, int
, list
, set
, dict
, etc.). To fix your current interpreter session, run:
del print
which will remove the print
variable shadowing the built-in print
function, restoring the original print
function. Then that line will run fine.
Upvotes: 3