Hacker News new | past | comments | ask | show | jobs | submit login

  "My name is {}, I'm {}'{}'' tall and live in {}".format(name, location, feet, inches)
This error is much better hidden than in the equivalent:

  f"My name is {name}, I'm {location}'{feet}'' tall and live in {inches}."



I did mention named parameters, you are using positional parameters to make your point. You don't even list the variables in your example. That seems pretty implicit to me.

I think this is more explicit:

"My name is {name}, I'm {feet} tall and live in {location}.".format(name="Bob", location="USA", feet=7)


Your example is not representative because you're using literals.

Your actual example would be:

    "My name is {name}, I'm {feet} tall and live in {location}.".format(name=name, location=location, feet=feet)
And with f-strings:

    f"My name is {name}, I'm {feet} tall and live in {location}."
f-strings is clearly more readable, concise and actually faster to run.


The literals were just an example. And personally I find it more explicit, which is my original point.

If its faster to run, then fair enough.


Using your example, I think

"My name is {name}, I'm {feet} tall and live in {location}.".format(name="Bob", location="USA", feet=7)

is less explicit than

"My name is Bob, I'm 7 feet tall and live in USA."


and that last one is faster to run ;-)


Yes it is.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: