Python - 字符串格式化(%和format())

版权声明:转载请注明出处 https://blog.csdn.net/qq_42292831/article/details/91485255
print("%sDEF"%"ABC")
print("%d456%d"%(123,789))
a = "%d456%d"%(123,789)
print(a,end="\n\n")

print("{}DEF".format("ABC"))
print("{0}DEF".format("ABC"))
print("{}456{}".format(123,789))
print("{0}456{1}".format(123,789))
b = "{}456{}".format(123,789)
print(b)

 运行结果:

猜你喜欢

转载自blog.csdn.net/qq_42292831/article/details/91485255