python
5 years, 9 months ago
a = 5
b = 10
c = 15
# Basic usage
print('the value of a is {} and b is {}'.format(a, b))
###output is the value if a is 5 and b is 10
# Here the index of a is 0, b's 1 and c's 2
print('the value of a is {2} and b is {0} and c is {1}'.format(a, b, c))
###output is the value if a is 15 and b is 5 and c is 10
#we can use key value pairs to assign to format
print('Hello, {name} {Greets}'.format(name='Koder', Greets='Welcome to my blog'))
###output is Hello, Koder Welcome to my blog
##You can use format with the mix of indices and key value pairs
print('Hello {Name}, Your lucky number is {0}'.format(7, name='Koder1'))
###output is Hello Koder1, Your lucky number is 7
0 Comments
Please Login to Comment Here