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

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

    The inverse is ( to convert a list of int to list of string ) : map ( str, results)

  3. 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: …

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

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

  6. Convert a string to integer with decimal in Python

    I believe this is a useless bug that should be corrected in Python. int('2') --> 2 That converts the string '2' into an the integer 2. int(2.7) --> 2 Converts a float to an int. int('2.7') SHOULD convert to 2. This is …

  7. Converting String to Int using try/except in Python

    Nov 10, 2011 · So I'm pretty stumped on how to convert a string into an int using the try/except function. Does anyone know a simple function on how to do this? I feel like I'm still a little hazy on string and i...

  8. python - How can I convert string values from a dictionary, into int ...

    Mar 16, 2011 · Check if the element is a dictionary, if it is, use the recursive update. If it's able to be converted into a float or int, convert it and modify the value in the dictionary. There isn't any built-in …

  9. Python: How do I convert an array of strings to an array of numbers?

    Mar 15, 2011 · MATHY people call Python lists an array. A 2-d list/array is a matrix. I believe the origin is from linear algebra.

  10. python - How to convert an integer to a string in any base? - Stack ...

    The below provided Python code converts a Python integer to a string in arbitrary base ( from 2 up to infinity ) and works in both directions. So all the created strings can be converted back to Python …