Python字符串格式化
1 # 用.format格式化字符串 2 3 "{} am {}".forma("I", "happy") 4 5 # 可以重复参数以节省时间 6 "{0} am {1}, {2} is {1}".format("I","happy","she") 7 8 # 如果不想通过数参数,可以用关键字 9 "{name} is hungry, and wants to eat {food}".format(name="Tom", food="fruit") 10 11 # 使用f格式化输出 12 print(f('{"I"} am {"happy"}'))
本文来自博客园,作者:术科术,转载请注明原文链接:https://www.cnblogs.com/shukeshu/p/14897807.html