About 94,900 results
Open links in new tab
  1. python - String formatting: % vs. .format vs. f-string literal - Stack ...

    For reference: Python 3 documentation for the newer format() formatting style and the older % -based formatting style.

  2. python - How do I escape curly-brace ( {}) characters characters in …

    The OP wants to keep curly-braces while you are removing them in your linked answer via .format () and your dictionary unpacking method. If you want to preserve {} in Python 3.6+ and you …

  3. How to format a floating number to fixed width in Python

    The format specifier inside the curly braces follows the Python format string syntax. Specifically, in this case, it consists of the following parts: The empty string before the colon means "take the …

  4. Format numbers to strings in Python - Stack Overflow

    Starting in Python 2.6 (meaning it works for 2.x and 3.x), there is an alternative: the str.format() method. Here are the equivalent snippets to the above but using str.format():

  5. python - f-strings vs str.format () - Stack Overflow

    I'm using the .format() a lot in my Python 3.5 projects, but I'm afraid that it will be deprecated during the next Python versions because of f-strings, the new kind of string literal. >>>...

  6. How can I fill out a Python string with spaces? - Stack Overflow

    Apr 15, 2011 · These string formatting operations have the advantage of working in Python v2 and v3. Take a look at pydoc str sometime: there's a wealth of good stuff in there.

  7. python - How do I pad a string with zeros? - Stack Overflow

    Rather, the Python documentation website behind that link was rewritten. Apart from that, the documentation used to have stronger wording, and literally states that str.format “should be …

  8. python - Convert floating point number to a certain precision, and …

    Mar 7, 2013 · Python 3.6 Just to make it clear, you can use f-string formatting. This has almost the same syntax as the format method, but make it a bit nicer. Example: print(f'{numvar:.9f}') More …

  9. Using multiple arguments for string formatting in Python (e.g., '%s ...

    Aug 3, 2010 · On str.format instead of % A newer alternative to % operator is to use str.format. Here's an excerpt from the documentation: str.format(*args, **kwargs) Perform a string …

  10. Convert int to binary string in Python - Stack Overflow

    Apr 30, 2019 · Python actually does have something already built in for this, the ability to do operations such as '{0:b}'.format(42), which will give you the bit pattern (in a string) for 42, or …