About 282,000 results
Open links in new tab
  1. 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:

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

    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 that the input …

  3. 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 variable is …

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

  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 returned. Edit: …

  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. How to get integer values from a string in Python?

    Suppose I had a string string1 = "498results should get" Now I need to get only integer values from the string like 498. Here I don't want to use list slicing because the integer values may incr...

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

    Jul 30, 2022 · 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. Both strings will …

  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. How can I check if string input is a number? - Stack Overflow

    What do you mean "not floats"? int() can only return an integer. Do you mean userInput could be a float? That's only true in Python 2, in which case don't use input() since it evaluates user input which is …