About 405,000 results
Open links in new tab
  1. What does 'f' mean before a string in Python? - Stack Overflow

    Oct 4, 2019 · 5 String starting with f are formatted string literals. Suppose you have a variable: pi = 3.14 To concatenate it to a string you'd do: s = "pi = " + str(pi) Formatted strings come in …

  2. python - What is print (f"...") - Stack Overflow

    Jul 22, 2019 · 148 The f means Formatted string literals and it's new in Python 3.6. A formatted string literal or f-string is a string literal that is prefixed with f or F. These strings may contain …

  3. python - Using f-string with format depending on a condition

    Aug 16, 2018 · How can I use f-string with logic to format an int as a float? I would like if ppl is True to format num to 2 decimal places, and if ppl is False to rformat it as whatever it is. …

  4. python - String formatting: % vs. .format vs. f-string literal - Stack ...

    python performance string-formatting f-string edited Aug 17, 2022 at 7:09 Karl Knechtel 61.4k 14 133 193

  5. python - How can I use f-string with a variable, not with a string ...

    Unlike f -strings, the {...} placeholders are not expressions and you can't use arbitrary Python expressions in the template. This is a good thing, you wouldn't want end-users to be able to …

  6. python - How can I use newline '\n' in an f-string to format a list of ...

    Jun 27, 2017 · The other answers give ideas for how to put the newline character into a f-string field. However, I would argue that for the example the OP gave (which may or may not be …

  7. python - What are use cases for nested f-strings - Stack Overflow

    I don't think formatted string literals allowing nesting (by nesting, I take it to mean f'{f".."}') is a result of careful consideration of possible use cases; I'm more convinced it's just allowed in …

  8. python - How do I convert a string into an f-string? - Stack Overflow

    f-strings are new in python 3.6 and are literals not callables. I know how to get something that works similarly. What I want is to make an existing string (possibly loaded from a file) and have …

  9. python - Fixed digits after decimal with f-strings - Stack Overflow

    Is there an easy way with Python f-strings to fix the number of digits after the decimal point? (Specifically f-strings, not other string formatting options like .format or %) For example, let's s...

  10. python - How to escape curly-brackets in f-strings? - Stack Overflow

    I have a string in which I would like curly-brackets, but also take advantage of the f-strings feature. Is there some syntax that works for this? Here are two ways it does not work. I would like to