How do you escape % when formatting a string?

irstas at gmail.com irstas at gmail.com
Mon Apr 2 15:56:17 EDT 2007


On Apr 2, 10:52 pm, irs... at gmail.com wrote:
> On Apr 2, 10:50 pm, "erikcw" <erikwickst... at gmail.com> 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
>
> Use %%.
>
> >>> "%d%%" % 75
>
> "75"

Oups, I made a typo in the result which should've been "75%"




More information about the Python-list mailing list