About 50 results
Open links in new tab
  1. How do I check if a string represents a number (float or int)?

    A number, if the number is valid; A status code (e.g., via errno) or exception to show that no valid number could be parsed. C (as an example) hacks around this a number of ways. Python lays it out …

  2. 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 duplicate …

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

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

  4. python - How to print a number using commas as thousands …

    How do I print an integer with commas as thousands separators? 1234567 1,234,567 It does not need to be locale-specific to decide between periods and commas.

  5. Get only numbers from string in python - Stack Overflow

    Feb 15, 2015 · If you want to keep it simpler avoiding regex, you can also try Python's built-in function filter with str.isdigit function to get the string of digits and convert the returned string to integer. This …

  6. python - Count the number of occurrences of a character in a string ...

    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.

  7. python - Split string every nth character - Stack Overflow

    Feb 28, 2012 · Using the re (regex) Module: Python’s re module provides a function called findall (), which can be used to find all occurrences of a pattern in a string. We can use this function with a …

  8. python - Check if a string contains a number - Stack Overflow

    Nov 8, 2013 · I need to enter a string and check to see if it contains any numbers and if it does reject it. The function isdigit() only returns True if ALL of the characters are numbers.

  9. 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:

  10. 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 89" …