if you want to choose string formatting, like many of the suggested ones, and you are using Python at least 2.6, take care of string formatting in your newest incarnation. Instead:
["%04d" % idx for idx in xrange(10000)]
It is suggested to choose:
["{0:0>4}".format(i) for i in xrange(1000)]
This is because the latter method is used in Python 3 as a standard idiom for formatting strings, and I think it is a good idea to increase code portability for future versions of Python.
As someone said in the comments, in Python 2.7+ there is no need to specify a positional argument, so this is also true:
["{:0>4}".format(i) for i in xrange(1000)]
Paolo source share