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

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

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

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

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

  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 …

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

    283 The standard way is to use format string modifiers. These format string methods are available in most programming languages (via the sprintf function in c for example) and are a handy tool …

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

  10. python - How to convert an int to a hex string? - Stack Overflow

    Also you can convert any number in any base to hex. Use this one line code here it's easy and simple to use: hex(int(n,x)).replace("0x","") You have a string n that is your number and x the …