Originally Posted by
durand
Is it possible in python to print a string with variables embedded inside it. I'm new to python so I'm not even sure how you would show that some word is a variable except when they are separate.
Yes, you can. Example code:
Example code:
Code:
name = raw_input("What is your name? ")
age = raw_input("What is your age? ")
rank = raw_input("How rank are you? ")
if age.isdigit():
print "Hello %s, you are %i years old and are %s rank" % (name,int(age),rank)
else:
print "%s, \"%s\" is not an age!" % (name,age)
This sort of thing can be done with strings in many situations. It is similar to printf() in C if you know that language.
Code:
output = '<smiley shortcut="%s" checksum="%s" filename="%s"/>' % (shortcut,checksum,filename)
Bookmarks