Search code examples
pythonpython-2.7printingstring-formatting

Printing multiple variables inside quotes in python


I am trying to print multiple variables in a print statement but I want all the variables to be printed in double quotes

While using normal formatting I am able to get it printed without the double quotes (%s) but unable to get it printed inside the double quotes while using the statement as below

print "Hostname='"%s"' IP='"%s"' tags='"%s"'"%(name,value["ip"],tags)

Solution

  • You should enclose the entire string with single quotes (') and each %s with double quotes ("):

    print 'Hostname="%s" IP="%s" tags="%s"' % (name, value["ip"], tags)