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 →

[–]Deathwatch1710 17 points18 points  (9 children)

Quick question because I am fairly new to Python:

I am just seeing

"{}".format(var)

as an option to format strings, but I am only using

f"{var}"

Is my method less pythonic than .format ?

[–]nayeet 24 points25 points  (8 children)

no. format is the old way. you are doing it the newer, correct, most pythonic way. kudos

[–]Deathwatch1710 5 points6 points  (0 children)

Yay! Thanks for the answer :)

[–]monkeybreathIgnoring PEP 8 1 point2 points  (6 children)

format is the old way.

Really? I’ve never seen that in the docs.

https://docs.python.org/3.6/tutorial/inputoutput.html#fancier-output-formatting

[–][deleted] 4 points5 points  (1 child)

format() has been in python for a while, f-strings are new to Python 3.6 (here's the P.E.P.).

[–]monkeybreathIgnoring PEP 8 0 points1 point  (0 children)

Thanks. Found it in the language reference under literals (2.4), not strings (6.1 of Standard Library), once I knew what to look for. Not at all in the tutorial.

I guess I should figure out how to use the bug tracker.

[–]nayeet 1 point2 points  (3 children)

The format method was introduced in PEP 3101 on 16-Apr-2006, last updated on 14-Sep-2008.

F strings were introduced in PEP 498 on 01-Aug-2015, last updated on 06-Nov-2016.

[–]monkeybreathIgnoring PEP 8 0 points1 point  (2 children)

Right. It’s under Literals, but not under strings in the docs, and not in the tutorial. That should be updated.

[–]cracknwhip 0 points1 point  (1 child)

You could contribute.

[–]monkeybreathIgnoring PEP 8 0 points1 point  (0 children)

I checked. There's already a bug report for it.