Mastering Python — Section 4: (f-string) An efficient and easy-to-read way to format strings in
<p>In Python 3.6 and above, strings prefixed with <code>f</code> or <code>F</code> are known as f-strings (formatted string literals). This is a modern and faster way to format strings compared to using the <code>.format()</code> method or the <code>%</code> operator.</p>
<p>In f-strings, you can evaluate expressions inside curly braces <code>{}</code> directly within the string. The expression will be replaced by its evaluated value.</p>
<p>Example:</p>
<pre>
book_number = 1
print(f"Book number {book_number} is Python for Beginners."</pre>
<pre>
book_number = 1
print(f"Book number {book_number} is Python for Beginners.")</pre>
<p>Outputt</p>
<pre>
Book number 1 is Python for Beginners.</pre>
<p>When you write <code>print(f"Book number {1} is")</code>, the number 1 inside the curly braces <code>{}</code> will remain as the number 1. So, the output will be:</p>
<pre>
Book number 1 is</pre>
<p>You can also perform operations or call functions within the curly braces. For example:</p>
<pre>
print(f"The result of 2 + 2 is {2 + 2}.")</pre>
<p>Output:</p>
<pre>
The result of 2 + 2 is 4.</pre>
<p>F-strings are an efficient and easy-to-read way to format strings in Python.</p>
<p><a href="https://medium.com/@selikurdev/mastering-python-section-4-f-string-an-efficient-and-easy-to-read-way-to-format-strings-in-88829f35c528">Click Here</a></p>