The format method
The format method substitutes data using string formatting. In the method parameter, we set the value we need, which will fill the empty curly brackets in the string.
Syntax
string.format(value)
Example
Let's substitute a string value into our string:
txt = 'This is {}'
print(txt.format('text'))
Result of code execution:
'This is text'
Example
You can also specify a number:
txt = 'This is {}'
print(txt.format(123))
Result of code execution:
'This is 123'
Example
Now let's substitute a list element into the string:
txt = 'This is {}'
lst = ['a', 'b', 'c']
print(txt.format(lst[0]))
Result of code execution:
'This is a'