Lonto81
Lonto81

Reputation: 93

TypeError: NoneType object is not callable

I'm new to Python and I can't figure out what's wrong with this code. Everything works except that instead of printing out my print statement I get this error instead, ""and your favorite color is %s")(name, quest, color) TypeError: 'NoneType' object is not callable" Here's my code below.

name = input("What is your name?")
quest = input("What is your quest?")
color = input("What is your favorite color?")

print ("Ah, so your name is %s, your quest is %s,"
"and your favorite color is %s")(name, quest, color)

Upvotes: 3

Views: 36947

Answers (1)

Ryan Haining
Ryan Haining

Reputation: 36802

Your string format syntax is wrong

print("Ah, so your name is %s, your quest is %s and your favorite color is %s" % (name, quest, color))

Though you may prefer the newer .format style

print("Ah, so your name is {}, your quest is {} and your favorite color is {}".format(name, quest, color))

Or, as of Python3.6 you can use f-strings (note the f before the first " below)

print(f"Ah, so your name is {name}, your quest is {quest} and your favorite color is {color}")

The error you are receiving is due to the evaluation of print. Given the error I'm assuming you're using python3 which is doing something like this

print('hello')()

This is evaluated as

(print('hello'))()

which will call print with the argument 'hello' first. The print function returns None so what happens next is

(None)()

or equivalently

None()

None is not callable, leading to your error

Upvotes: 18

Related Questions