.format vs. %
rantingrickjohnson at gmail.com
Mon Jan 2 20:51:48 EST 2012
On Dec 31 2011, 12:19 pm, davidfx <dgeorge2... at gmail.com> wrote:
> Hello everyone,
> I just have a quick question about .format and %r %s %d.
> Should we always be using .format() for formatting strings or %?
ALWAYS use the format method over the old and dumpy string
interpolation. Why? Well because the format method is so much more
powerful, elegant, and the way of the future. Some might argue that
format is slower than interpolation (and i can't comment in favor of
either) HOWEVER, if speed is your concern than interpolation is NOT
> If I wanted to put .format into a variable, how would I do that.
That question has been answered many times in this thread already.
You may find the format spec to be cryptic at first. Well, most find
regexes cryptic also -- but would anyone recommend NOT using regexes
just because of crypti-ness? I think not. It's a non-starter.
More information about the Python-list