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

  2. python - How do I pad a string with zeros? - Stack Overflow

    What is the most pythonic way to pad a numeric string with zeroes to the left, i.e., so the numeric string has a specific length? str.zfill is specifically intended to do this:

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

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

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

  6. python - Display number with leading zeros - Stack Overflow

    1990 In Python 2 (and Python 3) you can do: number = 1 print("%02d" % (number,)) Basically % is like printf or sprintf (see docs). For Python 3.+, the same behavior can also be achieved with …

  7. How to get integer values from a string in Python?

    Suppose I had a string string1 = "498results should get" Now I need to get only integer values from the string like 498. Here I don't want to use list slicing because the integer values may incr...

  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. python - Best way to format integer as string with leading zeros ...

    The way interpreter (python is not compiled) parses ints is different for ints starting with a leading 0. If a number starts with 0 then it is considered as 8-nary number.

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