Reading Time: 1 minutes
Generate XML by surrounding text by a tag name in Python
Write a Python program to generate XML by surrounding text by a tag name. For example, generateXML('firstname', 'Ethan') should return '<firstname>Ethan</firstname>'.
Generate XML by surrounding text by a tag name
def generateXML(tagName, contentText): return '<{}>{}</{}>'.format(tagName, contentText, tagName) print(generateXML('firstname', 'Ethan')) # <firstname>Ethan</firstname> print(generateXML('lastname', 'Hunt')) # <lastname>Hunt</lastname>