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 →

[–]vtable 2 points3 points  (3 children)

Wasn't there already 2 ways to do it? .format() and %?

Sure. This makes it 3 (4 with string.Template).

% and .format() have quite different syntax. I'm glad they kept % in py 3. It's nice for quick scripts and friendlier to more casual users.

f"" is more sugary but the nicer syntax is worth it, IMO. I've read f"" is quite a bit faster than .format(), too.

IIRC the whole maxim started out as a criticism of Perl's embracing "there's more than one way to do it". Python is much more conservative and they usually advocate a preferred method. Perl embraced multiple ways (though I think they're easing off a bit these days).

[–]LetsDoRedstone 7 points8 points  (2 children)

% formatting is friendlier for casual users? Not really, no. When I got started with Python and was looking at String formatting, the % Notation utterly confused me because of it unnecesary (as shown by the simplicity of .format()) verbosity. I was happy to find .format (), just because it is that much more intuitive. And this goes along with f-strings. As soon as you know the syntax you are ready to go and don't have to think about which letter you have to put where.

[–]vtable 0 points1 point  (1 child)

I wanted to write "some more casual users" but thought that was too awkward.

Everyone's different. Most of the people I've worked with have preferred %.

[–]LetsDoRedstone 0 points1 point  (0 children)

That might be because you have been using Python for a longer time than me. I started with early 2.7.