About 303,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 …

  2. Convert integer to string in Python - Stack Overflow

    Jun 23, 2019 · 72 There is no typecast and no type coercion in Python. You have to convert your variable in an explicit way. To convert an object into a string you use the str() function. It works …

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

    Here, append () is used to add items ( i.e integer version of string (i) in this program ) to the end of the list (b). Note: int () is a function that helps to convert an integer in the form of string, back to …

  4. python - How can I check if a string represents an int, without …

    The built-in int () function silently truncates the fractional part of a floating point number and returns the integer part before the decimal, unless the floating point number is first converted …

  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 …

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

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

  7. python - How to convert a string to a number if it has commas in …

    It will be converted to string first (if it is a list, for example from Beautiful soup); then to int, then to float. It goes as far as it can get. In worst case, it returns everything unconverted as string. def …

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

    Oct 16, 2008 · Worth repeating "Letting int infer If you pass 0 as the base, int will infer the base from the prefix in the string." How to convert from hexadecimal or decimal (or binary) to integer …

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

  10. python - ValueError: invalid literal for int () with base 10 ...

    Here you are trying to convert a string into int type which is not base-10. you can convert a string into int only if it is base-10 otherwise it will throw ValueError, stating invalid literal for int () with …