Mega Code Archive

 
Categories / Python / Development
 

Print variable into a string

x = 42 y = 3.14 z = "george" print 'result = %d' % x                 # prints: result = 42 print 'answers are: %d %f' % (x,y)      # prints: answers are: 42 3.14 print 'hello %s' % z                    # prints: hello george