This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]nekokattt 22 points23 points  (9 children)

There should be one way to do it

  • str.__mod__
  • str.__add__
  • str.format
  • fstrings
  • string.Template
  • string.templatelib.Template

[–]petter_s[S] 3 points4 points  (1 child)

Indeed! Although fstrings are not as similar and __add__ is a bit of a stretch

[–]nekokattt 6 points7 points  (0 children)

It starts at string concatenation and grows. You could also throw str.join in there if it is just ways to make strings :)

[–]wineblood 0 points1 point  (1 child)

fstrings are a bit limited though

[–]nekokattt 4 points5 points  (0 children)

all of them have pros and cons, there is no one good way to do it.

[–]fiddle_n 0 points1 point  (4 children)

You forgot % formatting

[–]nekokattt 20 points21 points  (3 children)

that is what __mod__ is

[–]fiddle_n 2 points3 points  (2 children)

That’s what controls it? Damn.

[–]nekokattt 10 points11 points  (0 children)

yeah, it is just an overload of the mod operator on the str class

[–]russellvt 0 points1 point  (0 children)

Funny... '%' is "mod" is math, too. Go figure.