About 302,000 results
Open links in new tab
  1. String formatting in Python - Stack Overflow

    Use Python 3 string formatting. This is still available in earlier versions (from 2.6), but is the 'new' way of doing it in Py 3. Note you can either use positional (ordinal) arguments, or named …

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

    Tested again in Python 3.7.2 in July 2019. Result: > format: 0.86600608 > %: 0.630180146 There is not much difference. I guess Python is improving gradually. Edit 2: After someone …

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

    Aug 3, 2010 · For completeness, in python 3.6 f-string are introduced in PEP-498. These strings make it possible to. embed expressions inside string literals, using a minimal syntax. That …

  4. How do I turn a python datetime into a string, with readable …

    Here is how you can accomplish the same using python's general formatting function... >>>from datetime import datetime >>>"{:%B %d, %Y}".format(datetime.now()) The formatting …

  5. python - How to print formatted string in Python3? - Stack Overflow

    Nov 11, 2014 · Started with Python 3.0 but is backported to 2.6+ print("So, you're {} old, {} tall and {} heavy.".format(age, height, weight)) #or for pinning(to skip the variable expanding if you …

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

    Here is an example: PYTHON FIXED POINT CONVERTER Configuration: -Type of conversion: Floating to fixed point -Signedness: Signed -Total bits: 32 -Fractional bits: 31 WARNING: 1.0 …

  7. What does %s mean in a Python format string? - Stack Overflow

    Mar 1, 2022 · Actually that PEP says "In Python 3.0, the % operator is supplemented by a more powerful string formatting method" and that it is backported to Python 2.6. Where I come from …

  8. Format numbers to strings in Python - Stack Overflow

    Python 2.6+ It is possible to use the format() function, so in your case you can use: return '{:02d}:{:02d}:{:.2f} {}'.format(hours, minutes, seconds, ampm) There are multiple ways of using …

  9. How do I format a string using a dictionary in python-3.x?

    As Python 3.0 and 3.1 are EOL'ed and no one uses them, you can and should use str.format_map(mapping) (Python 3.2+): Similar to str.format(**mapping), except that mapping …

  10. python - How do I escape curly-brace ({}) characters characters in a ...

    Python 3.6+ (2017) In the recent versions of Python one would use f-strings (see also PEP498). With f-strings one should use double {{or }} n = 42 print(f" {{Hello}} {n} ") produces the desired …