4 ms·
So, like, just to point out, your example would be, with name Adam and age 10: "My Adam is, I am 10 old." Correcting your example: "My name is {name}, I
by aetherson 12y ago
So, like, just to point out, your example would be, with name Adam and age 10:
"My Adam is, I am 10 old."
Correcting your example:
"My name is {name}, I am {years} years old".format(name=name, years=years)
So to throw that out, that one line includes the word "name" four freaking times, and years four freaking times. You say you like the verbosity of it. Why? Would you like this format yet more?
"My name is {name=name}, I am {years=years} years old".format(name=name, years=years)
If not why not? It's yet more verbose.
I think that the reason that other people like the non-verbose format of:
"My name is {name}, I am {years} years old" # assuming the presence of local variables "name" and "years"
Is that, well, it's pretty obvious what's going on here, and repeating name and years a bunch more times do not, it seems, make it any more clear what's going on.
A reasonable argument might be that:
"My name is {name}, I am {years} years old".format()
Is more clear about what's going on. But repeating the variable names is not particularly elucidating.
- mcbetz 12y agoWell, I did not want to defend the way .format() works now. That's why I asked for the reasoning. Your reasonable argument sounds reasonable to me, I would certainly use it. But then my initial question is even more important: Why is this not the one Python way. What did the initial designers think?