but I don't want to print the trailing ".0"

Skip Montanaro skip at pobox.com
Thu May 1 21:18:44 EDT 2003


    Dan> What is the "in crowd" method to enhance s.py so I don't have to use
    Dan> sed to get what I want?

    Dan> $ cat s.py
    Dan> steps=(1500,1250,1000,625,500)
    Dan> for i in steps:
    Dan>     print i/100.0 #how do I enhance this line, please? what %f thingy?

How about

    steps = (1500, 1250, 1000, 625, 500)
    for i in steps:
        print "%g" % (i/100.0)

For more details, check out

    http://www.python.org/doc/current/lib/typesseq-strings.html

Skip





More information about the Python-list mailing list