I'm dealing with strings of the following form '000351'. Think of them as odometer readings. I want to increment them. For example I want to add 1 to '000345' and get '000346'.  The following python code does the job, but appears rather cumbersome. Is there a more elegant way to do this?  s='000345' t=int(s) t=t+1 int_to_6digit_string(t)   where the function int_to_6digit_string() is as follows  def int_to_6digit_string(i):     if i&lt;0 or i&gt;999999:         return 'argument out of bounds'     j=str(i)     if len(j) == 1:         return '00000'+j     elif len(j) == 2:         return '0000'+j     elif len(j) == 3:         return '000'+j     elif len(j) == 4:         return '00'+j     elif len(j) == 5:         return '0'+j     else:         return j
1551
What is a Pythonic way to pad a numeric string with zeroes to the left, i.e. so the numeric string has a specific length?
87535
Let's say I have an int with the value of 1. How can I convert that int to a zero padded string, such as 00000001?
50285
Is there a way to substring a string in Python, to get a new string from the third character to the end of the string?  Maybe like myString[2:end]?  If leaving the second part means 'till the end', and if you leave the first part, does it start from the start?
79687
This is a wild one: can anyone write a code that converts a number into the corresponding word? e.g.:  4 -&gt; 'four' 31 -&gt; 'thirty-one'   and so on. Obviously, it is not enough to build an array in which you can store the numbers and the word associated with it and then just print instead of the number the stored word. What complicates matters more, are numbers like 11 ('eleven'). I intend to use it for numbering equations. So, anybody up to it?
40138
What's the proper way to convert from a scientific notation string such as "1.234567E-06" to a floating point variable using C#?
28516
How do I format a number in Java? What are the &quot;Best Practices&quot;? Will I need to round a number before I format it?  32.302342342342343 =&gt; 32.30 .7323 =&gt; 0.73  etc.
95625
What is the formula for calculating the additional 3 characters needed to append to a 15 char Id in order to form its equivalent 18 char Id?   I have a situation where I need to compare 15 char Ids (uploaded by users) with their 18 char equivalents (stored in a local database), and it would be most efficient if I could convert the 15 char Ids to 18 chars before comparing (The 18 char Ids are PK fields in my local database, and while I could compare using a like query clause, it would be more efficient to convert to 18 chars and perform lookups based on those values).  The base algorithm would be great - even better is an C# implementation.
52629
Is there any way I can specify a standard or custom numeric format string to always output the sign, be it +ve or -ve (although what it should do for zero, I'm not sure!)
41641
What is the most efficient way of testing an input string whether it contains a numeric value (or conversely Not A Number)? I guess I can use Double.Parse or a regex (see below) but I was wondering if there is some built in way to do this, such as javascript's NaN() or IsNumeric() (was that VB, I can't remember?).  public static bool IsNumeric(this string value) {     return Regex.IsMatch(value, "^\\d+$"); }
1888
I want to do something like String.Format("[{0}, {1}, {2}]", 1, 2, 3) which returns:  [1, 2, 3]   How do I do this in Python?
40270
I need to calculate no of possible substrings containing "00" as a substring. I know the length of the binary string.  Eg: for a string of length 4, possible substrings are: 0000 0001 0010 0011 0100 1000 1001 1100  I just need the number of possible combinations, not enumerate all of them.
2168
I need to convert one into 1, two into 2 and so on.  Is there a way to do this with a library or a class or anything?
5995
When displaying the value of a decimal currently with .ToString(), it's accurate to like 15 decimal places, and since I'm using it to represent dollars and cents, I only want the output to be 2 decimal places.   Do I use a variation of .ToString() for this?
122421
There are a lot of articles around the web concerning python performance, the first thing you read: concatenating strings should not be done using '+': avoid s1+s2+s3, instead use str.join  I tried the following: concatenating two strings as part of a directory path: three approaches:   '+' which i should not do str.join os.path.join   Here is my code:  import os,time  s1='/part/one/of/dir' s2='part/two/of/dir' N=10000  t=time.clock() for i in xrange(N):     s=s1+os.sep+s2 print time.clock()-t  t=time.clock() for i in xrange(N):     s=os.sep.join((s1,s2)) print time.clock()-t  t=time.clock() for i in xrange(N):     s=os.path.join(s1,s2) print time.clock()-t   Here the results (python 2.5 WinXP)  0.0182201927899 0.0262544541275 0.120238186697   Shouldn't it be exactly the other way round ?
80374
If I have this string:     2+24*48/32   what is the most efficient approach for creating this list:     ['2', '+', '24', '*', '48', '/', '32']
2534
I am trying to calculate field test2 with only the numeric values from a string field test. The entire script is like:    def makestr(test)      list=[]      for s in test:          if s.isdigit():              list.append(s)      for a in list:          str=''.join(list)     But I keep getting an error:    Any ideas?
7244
How can I convert a string of bytes into an int in python?   Say like this: 'y\xcc\xa6\xbb'  I came up with a clever/stupid way of doing it:  sum(ord(c) &lt;&lt; (i * 8) for i, c in enumerate('y\xcc\xa6\xbb'[::-1]))   I know there has to be something builtin or in the standard library that does this more simply...  This is different from  for which you can use int(xxx, 16), but instead I want to convert a string of actual byte values.  UPDATE:  I kind of like James' answer a little better because it doesn't require importing another module, but Greg's method is faster:  &gt;&gt;&gt; from timeit import Timer &gt;&gt;&gt; Timer('struct.unpack("&lt;L", "y\xcc\xa6\xbb")[0]', 'import struct').timeit() 0.36242198944091797 &gt;&gt;&gt; Timer("int('y\xcc\xa6\xbb'.encode('hex'), 16)").timeit() 1.1432669162750244   My hacky method:  &gt;&gt;&gt; Timer("sum(ord(c) &lt;&lt; (i * 8) for i, c in enumerate('y\xcc\xa6\xbb'[::-1]))").timeit() 2.8819329738616943   FURTHER UPDATE:  Someone asked in comments what's the problem with importing another module. Well, importing a module isn't necessarily cheap, take a look:  &gt;&gt;&gt; Timer("""import struct\nstruct.unpack("&gt;L", "y\xcc\xa6\xbb")[0]""").timeit() 0.98822188377380371   Including the cost of importing the module negates almost all of the advantage that this method has. I believe that this will only include the expense of importing it once for the entire benchmark run; look what happens when I force it to reload every time:  &gt;&gt;&gt; Timer("""reload(struct)\nstruct.unpack("&gt;L", "y\xcc\xa6\xbb")[0]""", 'import struct').timeit() 68.474128007888794   Needless to say, if you're doing a lot of executions of this method per one import than this becomes proportionally less of an issue. It's also probably i/o cost rather than cpu so it may depend on the capacity and load characteristics of the particular machine.