python template literals code example
Example 1: f string repr
>>> color = "blue\ngreen"
>>> day = datetime.date(2020, 6, 4)
>>> f"Color is {color} and day is {day}"
'Color is blue\ngreen and day is 2020-06-04'
>>> f"Color is {color!r} and day is {day!r}"
"Color is 'blue\\ngreen' and day is datetime.date(2020, 6, 4)"
Example 2: template string python
print("Hello {planet}".format(planet='World'))
i = "Hello"
print("{word} World".format(word= i ))
Example 3: new python string formatting
>>> f'Hello, {name}!'
'Hello, Bob!'
Example 4: string template python
from string import Template
poem = Template('$x are red and $y are blue')
print(poem.substitute(x='roses', y='violets'))