Overview:
-
Formatting of a string involves dynamically forming a string with portions of the string already defined and portions to be filled dynamically as the program runs. e.g., Welcome User1, Welcome User2 - As the user logs in, the welcome message is dynamically composed.
-
The method format() fills in the place holders specified through {}. The place holders are replaced either through the index of the positional arguments or through the name of keyword arguments passed.
-
The format() method enables a Python programmer to get rid of formatting a string with format specifiers like %d, %s and others.
Example:
# Example Python program to dynamically compose # Using index of the positional arguments # z is the 1st argument which will go in the last # Using the name of the keyword arguments |
Output:
City x City y City z Welcome Alice |