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...

iphone 17 Launch 2025: Features, Price in India, Pros & Cons

iphone 17 Launch 2025: Features, Price in India, 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?

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

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.

AI: Boon or Curse? Advantages & Disadvantages Explained

AI: Boon or Curse? Advantages & Disadvantages Explained

Artificial Intelligence (AI) is no longer just a concept of the future—it is already shaping our present. From asking Alexa or Siri to play music, using Google Maps for directions, or experiencing personalized recommendations on Netflix, AI has become a part of our everyday life.

The Future of Technology: Quantum Computing and Its Ecosystem

The Future of Technology: Quantum Computing and Its Ecosystem

Quantum computing isn’t just another buzzword—it’s a completely new way of thinking about computers. Unlike our everyday laptops or phones that run on classical computing, quantum computers use the strange but powerful rules of quantum mechanics.

Tailwind CSS Cheat Sheet – Complete Utility Class Guide 2025

Tailwind CSS Cheat Sheet – Complete Utility Class Guide 2025

Tailwind CSS Cheat Sheet – Complete Utility Class Guide 2025

Expert-Level JavaScript Interview Q&A for 2025: Crack Advanced JS Interviews

Expert-Level JavaScript Interview Q&A for 2025: Crack Advanced JS Interviews

Get ready for tough coding interviews with this collection of advanced JavaScript interview questions and answers. Designed for experienced developers who want to master complex JS concepts and impress recruiters.

Share this article ...

💬WhatsApp📘Facebook💼LinkedIn🐦X