How to interpolate strings (formatting) in Python
How is string interpolation performed in Python?
String interpolation is the process of evaluating a string literal containing one or more placeholders, yielding a result in which the placeholders are replaced with their corresponding values.
There are three common ways to interpolate strings in Python:
format function
f-strings
% operator
String interpolation using format function
Name = 'John' Age = 32 print('Name: {}, Age: {}'.format(Name, Age))
Name: John, Age: 32
Name = 'John' Age = 32 print(f'Name: {Name}, Age: {Age}')
Name: John, Age: 32
Name = 'John' Age = 32 print(f'Name: %s, Age: %s' %(Name, Age))
Name: John, Age: 32