Skip to main content

All Questions

17 votes
1 answer
5k views

Dynamically Formatting Floats to Variable Decimal Places Using f-strings in Python [duplicate]

I've previously asked about dynamically adjusting the number of decimal places in a float when formatting with f-strings in Python. While I found similar questions that address aspects of dynamic ...
Mike C.'s user avatar
  • 1,931
6 votes
2 answers
941 views

Is line-joining unsupported by f-strings?

Is the following syntax not supported by f-strings in Python 3.6? If I line join my f-string, the substitution does not occur: SUB_MSG = "This is the original message." MAIN_MSG = f"This longer ...
JS.'s user avatar
  • 16.3k
308 votes
5 answers
304k views

Multiline f-string in Python

I'm trying to write PEP-8 compliant code for a domestic project and I have a line with an f-string that is more than 80 characters long: def __str__(self): return f'{self.data} - {self.time},\...
Owlzy's user avatar
  • 4,072
18 votes
5 answers
13k views

How to interpolate a list into an f-string in Python?

Say I have a function def foo(): return [1, 2, 3] I want to interpolate the result of the function into a string to get "001 002 003". I've tried this: f"{*foo():03d 03d 03d}" But it produced ...
planetp's user avatar
  • 16.2k