<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Brayden Mann</title>
    <description>The latest articles on DEV Community by Brayden Mann (@brayden_mann_1623).</description>
    <link>https://dev.to/brayden_mann_1623</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4192705%2F21914615-477a-419f-847b-c1052a7b9ea9.png</url>
      <title>DEV Community: Brayden Mann</title>
      <link>https://dev.to/brayden_mann_1623</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/brayden_mann_1623"/>
    <language>en</language>
    <item>
      <title>Why Choose F-Strings over String Concatenation in Python</title>
      <dc:creator>Brayden Mann</dc:creator>
      <pubDate>Sun, 18 Oct 2026 18:48:50 +0000</pubDate>
      <link>https://dev.to/brayden_mann_1623/why-choose-f-strings-over-string-concatenation-in-python-12im</link>
      <guid>https://dev.to/brayden_mann_1623/why-choose-f-strings-over-string-concatenation-in-python-12im</guid>
      <description>&lt;h2&gt;
  
  
  Thesis
&lt;/h2&gt;

&lt;p&gt;In the majority of cases an f-string is better than string concatenation because it allows for better readability and creates readable code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Type Coercion
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Your score is &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The f-string converts &lt;code&gt;score&lt;/code&gt; automatically, therefore &lt;code&gt;str()&lt;/code&gt; isn't needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Readability
&lt;/h2&gt;

&lt;p&gt;If the code is written with concatenation it reads:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Your score is&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By writing it this way the code has four separate parts starting with a string. Followed by the &lt;code&gt;+&lt;/code&gt; symbol to create the concatenation. Then there is a data type conversion from either integer or float to a string. The code ends with a variable within parentheses that needed to be converted. Written as an f-string the same line is a function followed by the f prefix. Then a string that held two curly braces to place the name of the variable being converted. It makes for quicker and cleaner read. It also allows you to complete the entire code in one string instead of two. For these reasons I recommend f-strings are used in these cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  When Concatenation Still Wins
&lt;/h2&gt;

&lt;p&gt;One situation where concatenation still makes sense is if the user is building a string piece by piece in a loop. When building this type of code each pass appends one line, so the message grows as the loop runs.&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
