All posts
postJune 2, 2026

Python f-strings — string formatting that does not suck

#python#f-strings#basics
python
user = "alice"
rows = 1547893
duration = 12.3456

print(f"User {user} processed {rows:,d} rows")
# User alice processed 1,547,893 rows

print(f"Took {duration:.2f}s")
# Took 12.35s

date = "2026-06-02"
print(f"s3://bucket/raw/{date}/data.parquet")

f-strings let you embed Python expressions directly inside string literals by prefixing the string with f. Anything inside curly braces gets evaluated and inserted.

In data engineering you use f-strings constantly: building log messages, constructing file paths with dates, formatting query parameters, generating reports. They are faster than .format() and far more readable. You can even add format specifiers — :.2f for two decimal places, :,d for thousands separators.