001、
>>> "{0}".format("xxx") ## 位置参数 'xxx' >>> "{0}.{1}.{2}".format("xxx", "yyy", "zzz") 'xxx.yyy.zzz' >>> "/t{0}.{1}.{2}".format("xxx", "yyy", "zzz") '/txxx.yyy.zzz' >>> "{0}./n{1}.{2}".format("xxx", "yyy", "zzz") 'xxx./nyyy.zzz' >>> print("{0}./n{1}.{2}".format("xxx", "yyy", "zzz")) xxx. yyy.zzz
002、
>>> "{a}.{b}.{c}".format(a = "aaa", b = "bbb", c = "ccc") ## 关键字参数 'aaa.bbb.ccc' >>> "{a}.{b}.{c}".format(a = "ccc", b = "bbb", c = "aaaa") 'ccc.bbb.aaaa' >>> "/t{a}.{b}.{c}".format(a = "ccc", b = "bbb", c = "aaaa") '/tccc.bbb.aaaa' >>> print("/t{a}.{b}.{c}".format(a = "ccc", b = "bbb", c = "aaaa")) ccc.bbb.aaaa
当同时出现位置参数和关键字参数时, 位置参数应写在关键字参数的前面。
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/280476.html