#The {} are replaced by the vairables after .format
new_string = "{} is string 1 and {} is string 2".format("fish", "pigs")
Name = 'Tame Tamir'
Age = 14
Formatted_string = 'Hello, my name is {name}, I am {age} years old.'.format(name=Name,age=Age)
# after the formatting, the variable name inside the {} will be replaced by whatever you declare in the .format() part.
print(Formatted_string) # output = Hello, my name is Tame Tamir, I am 14 years old.
print('The {2} {1} {0}'.format('fox', 'brown', 'quick'))
result = 100/777
print('{newvar}'.format(newvar = result))
print('the result was {r:0.3f}'.format(r = result))
age = 36
txt = "his age is {}"
print(txt.format(age))
# use {}, where u want to place integer, or any other datatype.
# Use .formate at the end of string,
# and finally place data variable in parentheses
a = 123.1133
b = "Username"
c = True
print("a = {}".format(a))
print("b = {}".format(b))
print("c = {}".format(c))
# Python string арга .format() нь мөр дэх хоосон хаалт ({}) орлуулагчийг аргументуудаараа сольдог.
# Түлхүүр үгсийг орлуулагчид заасан бол аргын харгалзах нэртэй аргументуудаар солино.
msg1 = 'Fred scored {} out of {} points.'
msg1.format(3, 10)
# => 'Fred scored 3 out of 10 points.'
msg2 = 'Fred {verb} a {adjective} {noun}.'
msg2.format(adjective='fluffy', verb='tickled', noun='hamster')
# => 'Fred tickled a fluffy hamster.'