String formatting (%)

P Adhia padhia at yahoo.com
Thu Apr 29 17:01:18 EDT 2004


alloydflanagan at comcast.net (A. Lloyd Flanagan) wrote in message 

Another version of a more compact function would be,

def commafy(s):
    return len(s) > 3 and "%s,%s" % (commafy(s[:-3]), s[-3:]) or s

Note that this function accepts string representation of an integer
(without checks of course).

P Adhia



More information about the Python-list mailing list