About 50 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 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:

  4. Convert integer to string in Python - Stack Overflow

    Jun 23, 2019 · Note: A variable in the format of string can be converted into an integer only if the variable is completely composed of numbers. In the same way, str () is used to convert an integer to …

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

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

  7. Convert a string to integer with decimal in Python

    Matt, 23.45678 isn't an integer. If you want Python to convert a string to an integer, make sure that you give it an integer. Arguments can be made either way about what the "right" thing is, and in the end …

  8. How to convert string to integer without using library functions in …

    Sep 25, 2017 · How to convert string to integer without using library functions in Python? Asked 8 years, 4 months ago Modified 3 years, 4 months ago Viewed 16k times

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

  10. Convert string / character to integer in python - Stack Overflow

    Jun 30, 2017 · I want to convert a single character of a string into an integer, add 2 to it, and then convert it back to a string. Hence, A becomes C, K becomes M, etc.