Format Strings
Format Strings
What if we want to join two separated strings?
We can perform concatenation to join two or more separate strings.
Example:
Output:
In the above example, we saw how one can concatenate two strings. But how can we concatenate a string and an integer?
Output:
As we can see, we cannot concatenate a string to another data type.
So what’s the solution?
We make the use of format() method. The format() methods places the arguments within the string wherever the placeholders are specified.
Example:
Output:
We can also make the use of indexes to place the arguments in specified order.
Example:
Output: