How do you escape % when formatting a string?

Bill Scherer bill.scherer at verizonwireless.com
Mon Apr 2 15:58:00 EDT 2007


erikcw wrote:
> Hi,
>
> I'm trying to format a string like so:
>
> string = "You have a 75% chance of success with %s, don't use %s" %(a,
> b)
>
> This gives me:
> TypeError: not enough arguments for format string
>
> I've tried 75\%, but that doesn't seem to help.  What am I missing?
>
> Thanks!
> Erik
>
>   
You escape % with %, of course:

string = "You have a 75%% chance of success with %s, don't use %s" %(a, b)



More information about the Python-list mailing list