About 150,000 results
Open links in new tab
  1. python - How do I pad a string with zeros? - Stack Overflow

    Dec 3, 2008 · 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: >>> …

  2. python - Print Combining Strings and Numbers - Stack Overflow

    Aug 18, 2012 · To print strings and numbers in Python, is there any other way than doing something like: first = 10 second = 20 print "First number is %(first)d and second number is …

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

    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 increase like these examples: string2 = "49867results should …

  4. python - How do I parse a string to a float or int? - Stack Overflow

    Dec 19, 2008 · Making ambiguous Python 2 octals compatible with Python 3. If you see an integer that starts with a 0, in Python 2, this is (deprecated) octal syntax. >>> 037 31 It is bad because …

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

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

    Jul 30, 2022 · This won't work with ffff because Python will think you're trying to write a legitimate Python name instead: >>> integer = ffff Traceback (most recent call last): File "<stdin>", line 1, …

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

    Safely evaluate an expression node or a string containing a Python literal or container display. The string or node provided may only consist of the following Python literal structures: strings, …

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

    All of these create the string "01": >python -m timeit "'{:02d}'.format(1)" 1000000 loops, best of 5: 357 nsec per loop >python -m timeit "'{0:0{1}d}'.format(1,2)" 500000 loops, best of 5: 607 nsec …

  9. Concatenating string and integer in Python - Stack Overflow

    Python is an interesting language in that while there is usually one (or two) "obvious" ways to accomplish any given task, flexibility still exists. s = "string" i = 0 print (s + repr(i)) The above …

  10. Converting String to Int using try/except in Python

    Nov 10, 2011 · Firstly, try / except are not functions, but statements. To convert a string (or any other type that can be converted) to an integer in Python, simply call the int() built-in function.

Refresh