Posts

Showing posts with the label programming

Python string formatting in print statements

#!/usr/bin/env python # Format using a dictionary print '%(language)s has %(number)03d quote types.' % { "language" : "Python" , "number" : 2 } # Format using a list print '%s has %03d quote types.' % ( "Python" , 2 ) # Best method print '{} has {} quote types.'.format ( "Python" , 2 ) Planning to post more code snippets this year to remind me of how to do various things in Python. Source: Pyformat