how does the % work?

John Gordon gordon at panix.com
Fri Mar 22 13:14:42 EDT 2013


In <mailman.3612.1363971987.2939.python-list at python.org> leonardo selmi <l.selmi at icloud.com> writes:

> hi guys

> i wrote this example :

> name = raw_input("What is your name?")
> quest = raw_input("What is your quest?")
> color = raw_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)

> but i get this error:  Traceback (most recent call last):
>   File "/Users/leonardo/print.py", line 5, in <module>
>     favourite color is %s.''') % (name, quest, color)
> TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

> how can i solve it?

Are you sure you've given us the exact code?  The printed text doesn't
exactly match.  ("favorite" vs. "favourite", three double-quotes vs
three single-quotes, etc.)

The error message also says that the print statement has a
close-parenthesis after the string and before the arguments, which may be
real problem.

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon at panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"




More information about the Python-list mailing list