Reputation: 11
I'm using python 3.3 and I'm trying to use the %s function but I get an error. I put
print("you're a %s man") % (input("put an adjective"))
then I run it in the module and get this
you're a %s man
put an adjectivefunny
Traceback (most recent call last):
File "C:\Users\Me\Desktop\coding\mie.py", line 1, in <module>
print("you're a %s man") % (input("put an adjective"))
TypeError: unsupported operand type(s) for %: 'NoneType' and 'str'
Upvotes: 1
Views: 53
Reputation: 250951
Correct syntax:
>>> print("you're a %s man" % input("put an adjective: "))
put an adjective: foo
you're a foo man
print()
returns None
in py3.x, so you were trying to apply string formatting to that None
.
>>> None % "foo"
Traceback (most recent call last):
File "<ipython-input-2-1aa4f0c0cbbd>", line 1, in <module>
None % "foo"
TypeError: unsupported operand type(s) for %: 'NoneType' and 'str'
Upvotes: 5