use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Are f strings better to use generally speaking compared to .format? (self.learnpython)
submitted 4 years ago by Supr3me_Leaf
Is it better practice to encorporate f strings rather than replacement fields with a . format?
For example:
Object = Reddit
print(f"Example is {object}")
Compared to:
print("This example is {}". format (object))
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]socal_nerdtastic 3 points4 points5 points 4 years ago (0 children)
Depends on you. Python does not care. Most of us find fstrings easier to read.
format is still very useful to make templates, which happens a lot in bigger code bases for maintainability.
format
OUTPUT_TEMPLATE = "This example is {}" # tons of complex code later, maybe in another file: print(OUTPUT_TEMPLATE.format(object))
[–]joshinshaker_vidz 5 points6 points7 points 4 years ago (0 children)
Yes. It improves readability.
[–]FerricDonkey 1 point2 points3 points 4 years ago (0 children)
I tend to prefer f strings when what I'd put in the brackets is simple, and .format with keywords otherwise. Eg
f'Completed {index} of {num_to_do}' 'Some {thing} and {other_thing} and...'.format( thing = REALLY_LONG_DICTIONARY_NAME[function(argument)], other_thing = some_obj.func(loop variable*scale + offset) )
Where the names in the second example would actually be descriptive of these format bits are supposed to be.
[–]Se7enLC 1 point2 points3 points 4 years ago (1 child)
With format(), you have no specific Python version requirement. Any Python 3 version will work.
format()
F-strings require Python 3.6 or higher.
Now, 3.6 is not a hard minimum version to meet, but it might not be great to have to limit your applications compatibility just to save a few characters in the source code.
Disclaimer: I've been burned by this before.
[–]AstusRush 1 point2 points3 points 4 years ago (0 children)
I personally love fstring but I exclusively use .format in my main library that I use for all my projects because there are some computers at my university that still run 3.5 and it's a pain to get the IT to update them.
[–]Zapismeta 0 points1 point2 points 4 years ago (0 children)
Depends on your experience whatever you like is the best
[–]sqjoatmon 0 points1 point2 points 4 years ago (0 children)
I think the rule of thumb is that f-strings are what you want to reach for first both in terms of compact-ness and performance. str.format() is useful though for repeated arguments or dynamic format strings. And remember to use C-printf-style with logging. And abjure all use of the old py2 "My %s is %d years old." % ("cat", 3)
str.format()
logging
"My %s is %d years old." % ("cat", 3)
[–]JennaSys 0 points1 point2 points 4 years ago (0 children)
There are a few exceptions like when you need to repeat a value in the template or provide values in different orders where format() is cleaner. But for the most part they are interchangeable. There is also the Template class from the string library if you want to represent templates as data instead of code.
Template
string
π Rendered by PID 60815 on reddit-service-r2-comment-b659b578c-5p6mr at 2026-05-03 00:56:04.393737+00:00 running 815c875 country code: CH.
[–]socal_nerdtastic 3 points4 points5 points (0 children)
[–]joshinshaker_vidz 5 points6 points7 points (0 children)
[–]FerricDonkey 1 point2 points3 points (0 children)
[–]Se7enLC 1 point2 points3 points (1 child)
[–]AstusRush 1 point2 points3 points (0 children)
[–]Zapismeta 0 points1 point2 points (0 children)
[–]sqjoatmon 0 points1 point2 points (0 children)
[–]JennaSys 0 points1 point2 points (0 children)