LCWD LogoLearn Code With DurgeshLCWD
HomeCoursesHandbooksBlogsContact
About LCWDAbout Durgesh Tiwari
Flex Box Hero
LearnCodeWithDurgesh Logo

Learn Code With Durgesh

Offering free & premium coding courses to lakhs of students via YouTube and our platform.

Explore

  • About Us
  • Courses
  • Blog
  • Contact
  • FlexBox Game

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Support

Contact

  • 📞 +91-9839466732
  • [email protected]
  • Substring Technologies, 633/D/P256 B R Dubey Enclave Dhanwa Deva Road Matiyari Chinhat, Lucknow, UP, INDIA 226028
© 2025 Made with ❤️ by Substring Technologies. All rights reserved.
Advanced Formatting with Python's f-strings

Advanced Formatting with Python's f-strings

By durgeshkumar8896 • Tue Jul 09 2024

Advanced Formatting with Python's f-strings

​Advanced Formatting with Python's f-strings


Today, we're diving into an advanced Python tip: f-strings!"

"F-strings, or formatted string literals, were introduced in Python 3.6. They make string formatting super easy and readable."

Basic example of using f-string:

name = "Alice"
age = 30
print(f"Hello, {name}. You are {age} years old.")

But, we can do much more with f-strings, let's have a look:

To format the number to desired decimal positions, e.g. : 

x=7869.3278654

print(f"{x:.4f}")

Here .4f formats the number to 4 decimal places

Change the alignment using <,>,^ :
 

name="John"

print(f"{name:>30}")

It will shift the value by 30 characters left

Show expressions inside the f-string: "F-strings can also evaluate expressions directly inside the curly braces!"
 

print(“Value of 5*4 is {5*4}”)

F-strings are powerful and flexible! Try these advanced formatting tricks in your next Python project

​

 

Share this article ...

💬WhatsApp📘Facebook💼LinkedIn🐦X

Trending Blogs...

I Used These 3 ChatGPT Prompts Daily in 2025 – Saved 3 Hours

I Used These 3 ChatGPT Prompts Daily in 2025 – Saved 3 Hours

Discover 3 powerful ChatGPT prompts that save you hours daily. Boost your productivity with AI in 2025.

Top 10 CSS Tips to Instantly Improve Your Design Skills (Beginner Friendly)

Top 10 CSS Tips to Instantly Improve Your Design Skills (Beginner Friendly)

Before writing CSS, know how it connects with HTML and why using external stylesheets is best.

Best Investment Apps in India 2025 – Start Investing Smartly from ₹100

Best Investment Apps in India 2025 – Start Investing Smartly from ₹100

Investing today has become easier than ever — thanks to powerful mobile apps that put the entire stock market, mutual funds, and digital assets right in your pocket .

Top 10 Highest-Paying Skills to Learn in 2025 (Earn ₹15–50 Lakh/Year)

Top 10 Highest-Paying Skills to Learn in 2025 (Earn ₹15–50 Lakh/Year)

Hey there! If you’re feeling the pressure of keeping up with today’s crazy-fast job market, you’re not alone. AI, automation, and digital transformation are flipping industries upside down, and the skills that used to land you a solid gig might not cut it anymore.

iPhone 17 Series Launch 2025 – India Price, Specs, Pros & Cons

iPhone 17 Series Launch 2025 – India Price, Specs, Pros & Cons

Apple has officially unveiled the **iPhone 17 series** on **September 9, 2025**, at its **“Awe Dropping” event**. The lineup includes **iPhone 17, iPhone 17 Air, iPhone 17 Pro, and iPhone 17 Pro Max**. With **120 Hz displays across all models, ultra-thin design, A19 chips, and camera upgrades**, Apple is raising the bar again.

Async/Await vs Promises in JavaScript – Which Should You Use in 2025?

Async/Await vs Promises in JavaScript – Which Should You Use in 2025?

Asynchronous programming is one of the most important topics in modern JavaScript development. Whether you’re building a web app, mobile application, or integrating APIs, you’ll often deal with operations that don’t finish instantly, such as fetching data or reading files.

Share this article ...

💬WhatsApp📘Facebook💼LinkedIn🐦X