Printf: print formatting [21 May 2009]
(Python environment -see also the unix man page "man printf")
strings: value
print "http://%s:234678" % "127.0.0.1"
It means that '%s' will be replace with the value '127.0.0.1':
http://127.0.0.1:234678
strings: variable
ip = '192.168.0.1' print "http://%s:234678" % ip
It means that '%s' will be replace with the value of the variable 'ip':
http://192.168.0.1:234678
list of strings
item = "you"
print "%s and %s" % ("me", item)
It means that the first '%s' will be replace with the first element of the list (the string 'me'; the second '%s' will be replaced with the second value of the list (the value of the variable 'item'). Be sure to use brackets.
me and you
integers and floating point numbers
It's the same but you must use '%d' for integers and '%f' for floating points.
