String {} and format() method in Python [Explained]
There are different ways to use the format method in Python:
I- using named indexes:
way1 = "Im {fname},and my age is {age}".format(fname = "John", age = 36)
print(way1)
Output:
Im John,and my age is 36
II- Using numbered indexes
way2 = "Im {0}, and my age is{1}".format("John",36)
print(way2)
Output:
Im John,and my age is 36
II- Using empty {}, with order:
way3 = "Im {}, and my age is {}".format("John",36)
print(way3)
Output:
Im John,and my age is 36