Skip to content

Instantly share code, notes, and snippets.

@k4ml
Last active May 19, 2016 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k4ml/8040050fd7a2b8b817e9d76f0fb4c9a8 to your computer and use it in GitHub Desktop.
Save k4ml/8040050fd7a2b8b817e9d76f0fb4c9a8 to your computer and use it in GitHub Desktop.
Python - TypeError: ‘str’ object is not callable

Python - TypeError: ‘str’ object is not callable

One common error faced by new python developer. The error message is a bit obscure if you don’t have fully grasp of the language — like what ‘callable’ is.

This error happen when you have code such as:-

print("Hello %s, your name is %s" (name, yourname))

On first glance, the code look correct. But the correct code is this instead:-

print("Hello %s, your name is %s" % (name, yourname))

What happen is that, forgetting to put the % after the string, effectively making it out like you want to call the string as function, like:-

  "hello"(name)

Which obviously wrong since string is not a function that you can call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment