nextRound
TechnologiesCoding ProblemsBookmarksLearning PathsLogin
nextRound
TechnologiesCoding ProblemsBookmarksLearning PathsLogin
nextRound

AI-powered interview preparation platform. Practice with curated questions, mock interviews, and personalized learning paths to crack your dream tech interview.

Quick Links

  • Technologies
  • Mock Interviews
  • Saved Questions
  • Pricing

Company

  • About Us
  • Contact Us

Legal

  • Privacy Policy
  • Terms of Use

© 2026 nextRound. All rights reserved.

Questions
4 of 14
1What are the common built-in data types in Python?
2what is an array
3Since Python 3.7, dictionaries preserve insertion order. How is this guaranteed internally, and what changed from earlier versions?
4What is the difference between str.format(), %-formatting, and f-strings? What are the performance and readability tradeoffs?
5When would you use collections.deque instead of a list, and why?
6Why are strings immutable in Python, and what performance implications does this have for repeated concatenation in a loop?
7What problem does collections.defaultdict solve, and how does it differ from using dict.setdefault?
8How would you efficiently remove duplicates from a list while preserving order?
9How would you design a Least Recently Used (LRU) cache using Python's built-in data structures?
10How does a Python dictionary achieve average O(1) lookup time internally?
11What is the difference between a list and a tuple, and when would you choose one over the other?
12What are the time complexities of common list operations (indexing, append, insert, pop, search)?
13What is the difference between a set and a frozenset?
14How does Python handle Unicode internally, and what is the difference between str and bytes?
PythonPython
Basics
Control Flow and Functions
Data Structures
Comprehensions & Functional Programming
Iterators, Generators & Decorators
Object-Oriented Programming
Exception Handling & Debugging
Concurrency & Parallelism
Performance & Optimization
Testing
Security
Modules, Packaging & Environment
Type Hinting & Modern Python
System Design & Architecture with Python
Best Practices & Design Patterns
Edge Cases & Tricky Interview Questions
04 / 14

What is the difference between str.format(), %-formatting, and f-strings? What are the performance and readability tradeoffs?

Difficulty: 3/10
Strings, Formatting, Performance

f-strings are fastest and most readable; format and % remain useful for dynamic templates

Percent formatting is the oldest style and is still common in logging. str.format() is more powerful and supports positional and keyword fields, but it is more verbose. f-strings evaluate expressions at runtime, are compiled into efficient bytecode, and are usually the fastest and most readable for local formatting. The main trade-off is that f-strings are eager: the expression is evaluated immediately, which matters for logging. For dynamic format strings from config or user input, str.format() or a templating engine is often safer.

  1. 1

    Use f-strings for local, fixed format strings and debugging.

  2. 2

    Use str.format() when the format template is dynamic or you need positional/keyword substitution.

  3. 3

    Use %-formatting mainly for compatibility or logging's lazy formatting style.

  4. 4

    Trade-off: f-strings are eager; logging with f-strings can waste work if the log level is disabled.

  5. 5

    Common mistake: using f-strings for user-controlled templates, which can be an injection risk if combined with eval-like behavior.

  6. 6

    Version note: f-strings landed in 3.6; = debug specifier in 3.8; nested quotes improved in 3.12.

javascript

Scenario Questions

0-2 years experience

  1. 1You need to format a user message with name and age. Which method?
  2. 2Why are f-strings often preferred?

2-5 years experience

  1. 1You need dynamic format strings from config. f-string vs str.format?
  2. 2You need logging with lazy evaluation. Which formatting?

5-8 years experience

  1. 1You need locale-aware formatting. Which method and why?
  2. 2You need to format many strings in a hot loop. Which is fastest and why?

8+ years experience

  1. 1Design a safe templating system that avoids injection and supports dynamic formats.
  2. 2You need to support Python 3.5 and 3.12. Which formatting features are available?

Follow-up Questions

  • Why can f-strings be worse than lazy logging?
  • How would you safely format a user-provided template?
Sharethis question

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.