468,549 Members | 2,383 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,549 developers. It's quick & easy.

How do you escape % when formatting a string?

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

Apr 2 '07 #1
3 26688
On Apr 2, 10:50 pm, "erikcw" <erikwickst...@gmail.comwrote:
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"
Apr 2 '07 #2
On Apr 2, 10:52 pm, irs...@gmail.com wrote:
On Apr 2, 10:50 pm, "erikcw" <erikwickst...@gmail.comwrote:
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%"

Apr 2 '07 #3

"erikcw" <er***********@gmail.comwrote in message
news:11*********************@y80g2000hsf.googlegro ups.com...
| 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?

The reference manual?

Apr 2 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ivo Woltring | last post: by
18 posts views Thread by Steve Litvack | last post: by
4 posts views Thread by Robert Manookian | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.