About 51 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. 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: …

  3. Python: Convert a string to an integer - Stack Overflow

    Mar 27, 2014 · Does anybody have a quickie for converting an unsafe string to an int? The string typically comes back as: '234\r\n'or something like that. In this case I want 234. If '-1\r\n', I want -1. I …

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

  6. Convert base-2 binary number string to int - Stack Overflow

    Jan 19, 2012 · I'd simply like to convert a base-2 binary number string into an int, something like this: >>> '11111111'.fromBinaryToInt () 255 Is there a way to do this in Python?

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

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

    8 You can easily convert string list items into int items using loop shorthand in python Say you have a string result = ['1','2','3'] Just do,

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

  10. Hex string to signed int in Python - Stack Overflow

    How do I convert a hex string to a signed int in Python 3? The best I can come up with is