About 211,000 results
Open links in new tab
  1. python - How do I pad a string with zeros? - Stack Overflow

    What is the most pythonic way to pad a numeric string with zeroes to the left, i.e., so the numeric string has a specific length? str.zfill is specifically intended to do this:

  2. How do I check if a string represents a number (float or int)?

    If what you are testing comes from user input, it is still a string even if it represents an int or a float. See How can I read inputs as numbers? for converting the input, and Asking the user for …

  3. How to extract numbers from a string in Python? - Stack Overflow

    Nov 27, 2010 · I would like to extract all the numbers contained in a string. Which is better suited for the purpose, regular expressions or the isdigit() method? Example: line = "hello 12 hi …

  4. Format numbers to strings in Python - Stack Overflow

    The OP & accepted answer focus on formatting time, but the OP question itself discusses formatting numbers to strings in Python. In many cases, the output requires additional data …

  5. python - Display a decimal in scientific notation - Stack Overflow

    Aug 2, 2011 · Should be accepted answer. f-strings is the future of python string formatting :) shayaan Over a year ago As an fyi to future readers like myself: if you don't care to control the …

  6. python - Display number with leading zeros - Stack Overflow

    1990 In Python 2 (and Python 3) you can do: number = 1 print("%02d" % (number,)) Basically % is like printf or sprintf (see docs). For Python 3.+, the same behavior can also be achieved with …

  7. How to convert string to number in python? - Stack Overflow

    Dec 3, 2022 · How to convert string to number in python? Asked 2 years, 10 months ago Modified 2 years, 10 months ago Viewed 22k times

  8. Convert integer to string in Python - Stack Overflow

    Jun 23, 2019 · 7 For someone who wants to convert int to string in specific digits, the below method is recommended. month = "{0:04d}".format(localtime[1]) For more details, you can …

  9. python - Count the number of occurrences of a character in a …

    How do I count the number of occurrences of a character in a string? e.g. 'a' appears in 'Mary had a little lamb' 4 times.

  10. python - How do I parse a string to a float or int? - Stack Overflow

    Dec 19, 2008 · For the reverse, see Convert integer to string in Python and Converting a float to a string without rounding it. Please instead use How can I read inputs as numbers? to close …