1# There are 3 different types of formatting.
2>>> name = "John"
3>>> age = 19
4>>> language = "python"
5>>> print(f"{name} of age {age} programs in {language}") # Commonly used.
6John of age 19 programs in python
7>>> print("%s of age %d programs in %s" %(name, age, language)) # %s for str(), %d for int(), %f for float().
8John of age 19 programs in python
9>>> print("{} of age {} programs in {}".format(name, age, language)) # Values inside .format() will be placed inside curly braces repectively when no index is specified.
10John of age 19 programs in python
11>>> print("{2} of age {1} programs in {0}".format(name, age, language)) # Index can be specified inside of curly braces to switch the values from .format(val1, val2, val3).
12python of age 19 programs in John
1# %s is used as a placeholder for string values you want to inject
2# into a formatted string.
3
4# %d is used as a placeholder for numeric or decimal values.
5
6# For example (for python 3)
7
8print ('%s is %d years old' % ('Joe', 42))
9# Would output
10
11>>>Joe is 42 years old
1a = "some text"
2print("%s < the string has been added here" % a)
3# OUTPUT: some text < the string has been added here
1from datetime import datetime
2
3'{:%Y-%m-%d %H:%M}'.format(datetime(2001, 2, 3, 4, 5))