Why do Ruby and Python have the % for formatting instead of "format"
I mean what makes %
look so much attractive compared to good old 开发者_运维问答.format
?!
I know this may be subjective, but I wonder if there is something about this.
They inherit them from C. Specifically, sprintf.
I'd assume they use %
because that's what the old C printf
format strings looked like.
It's just a piece of syntactic sugar, meant to make a common operation more terse. If you don't like it, you can use str.format() instead. I enjoy it because it makes printf()-style formatting stand out in the code.
精彩评论