print格式化输出 str.format()

虽然print()函数看起来好像很简单,但每次自己看到format时总会有点遗忘,所以这里把它记一下吧

print("hello{},我在这里{}".format("world","等你"))

默认情况下,format函数里的参数对应前面{}的位置,当然也可以自己决定,{}里的数字表示format函数参数的位置,如下

print("hello{1},我在这里{0}".format("world","等你"))

猜你喜欢

转载自www.cnblogs.com/moxiao/p/12055330.html