DOC: Add contributor guidance about f-strings
See original GitHub issueAs we dropped support for Python 3.5, can we use f-strings now instead of those dreadful str.format()
and '%s' % foo
thingies? 😃 I think in many situations, f-strings
are much more readable. What’s the other developers’ opinion on this?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Python 3's f-Strings: An Improved String Formatting Syntax ...
As of Python 3.6, f-strings are a great new way to format strings. ... Keep in mind that %-formatting is not recommended by...
Read more >fstring.help: Python f-string guide
f-strings are strings with an f in front of them: f". ... self-documenting expressions and debugging - some examples adapted from the "what's...
Read more >A Guide to Formatting with f-strings in Python - CIS Sandbox
This document will explain how to use the many options available with f-strings. Alignment. There are several ways to align variables in f-strings....
Read more >Issue 28739: PEP 498: docstrings as f-strings - Python tracker
I suggest adding "Bytestring literals and non-trivial f-strings do not become docstrings." as the second sentence.
Read more >The Complete Guide to Python f-Strings | Nick McCullum
Python f-strings are an improved method for formatting strings. This tutorial will teach you everything you need to know about using f-strings in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes the informal policy is that once we bump a requirement (incl. Python) we start using features available from that requirement where / when it’s useful to do so, assuming people agree that those features are useful compared to what we’ve been doing. For example
dict
maintains order in 3.6+np.mean(x, axis=0, keepdims=True)
instead ofnp.mean(x, axis=0)[np.newaxis]
once we bumped to a NumPy requirement that hadkeepdims
.format
over%
string because the benefits weren’t clear enough to everyone / it had its own drawbacksf
-syntax strings are probably nicer enough to prefer them going forward, though.Feel free to add some variant of this to the dev docs if you want to semi-formalize the policy
That’s exactly what I had in mind, sorry for not being clear in the beginning!
f-strings
in new code when appropriate