About 288,000 results
Open links in new tab
  1. python - How do I check if a string represents a number (float or …

    Editor's note: If what you are testing comes from user input, it is still a string even if it represents an int or a float. For converting the input, see How can I read inputs as numbers? For ensuring …

  2. Convert integer to string in Python - Stack Overflow

    Jun 23, 2019 · In the above program, int () is used to convert the string representation of an integer. Note: A variable in the format of string can be converted into an integer only if the …

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

    Dec 3, 2022 · 8 Convert the items to a integer if isdigit() returns True, else to a float. This can be done by a list generator:

  4. 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 …

  5. How can I convert a string to an int in Python? - Stack Overflow

    def convertStr(s): """Convert string to either int or float.""" try: ret = int(s) except ValueError: #Try float. ret = float(s) return ret That way if the int conversion doesn't work, you'll get a float …

  6. python - Convert all strings in a list to integers - Stack Overflow

    13 There are several methods to convert string numbers in a list to integers. In Python 2.x you can use the map function:

  7. Convert hex string to integer in Python - Stack Overflow

    Oct 16, 2008 · 59 Convert hex string to int in Python I may have it as "0xffff" or just "ffff". To convert a string to an int, pass the string to int along with the base you are converting from. …

  8. python - How can I check if a string represents an int, without …

    The built-in int () function silently truncates the fractional part of a floating point number and returns the integer part before the decimal, unless the floating point number is first converted …

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

    How do I pad a numeric string with zeroes to the left, so that the string has a specific length?

  10. python - Best way to format integer as string with leading zeros ...

    The way 004 is parsed by the compiler, and then represented in memory, is exactly the same as 4. The only time a difference is visible is in the .py source code. If you need to store …