various specialized string display formatting utilities test me with canned self-test or command-line arguments to doadd parens for negative moneyadd more features ""def commas( )""format positive integer-like for display with commas between digit groupings"xxx,yyy,zzz""digits str(nassert(digits isdigit()result 'while digitsdigitslast digits[:- ]digits[- :result (last ',resultif result else last return result def money(nnumwidth= currency='$')""format number for display with commas decimal digitsleading and signand optional padding"-xxx,yyy zznumwidth= for no space paddingcurrency='to omit symboland non-ascii for others ( pound= '\xa or '\ '""sign '-if else ' abs(nwhole commas(int( )fract (' fn)[- :number '% % % (signwholefractreturn '% %* (currencynumwidthnumberif __name__ ='__main__'def selftest()tests fails- tests + tests + * * for test in testsprint(commas(test)print(''tests - tests + tests + * ( * tests + tests +- - - tests +-( * )-( ** tests +( * )-( * for test in testsprint('% [% ](money(test )test)import sys if len(sys argv= selftest( advanced module topics