立即学习:https://edu.csdn.net/course/play/26755/340142?utm_source=blogtoedu
format函数:
1.默认方式:
text = "I am the {}. you are the {}."
print(text.format("first", "second"))
"""结果:
I am the first. you are the second. """
2.命名参数:
text = "I am the {first}. you are the {second}."
print(text.format(second = "second", first = "first"))
"""结果:
I am the first. you are the second. """
3.位置参数:
text = "I am the {1}. you are the {0}."
print(text.format("second", "first"))
"""结果:
I am the first. you are the second. """