相关疑难解决方法(0)

Python的打印方式:使用'格式'还是百分比形式?

在Python中,似乎有两种不同的生成格式化输出的方法:

user = "Alex"
number = 38746
print("%s asked %d questions on stackoverflow.com" % (user, number))
print("{0} asked {1} questions on stackoverflow.com".format(user, number))
Run Code Online (Sandbox Code Playgroud)

有没有一种方法可以优先于另一种方式?它们是等价的,有什么区别?应该使用什么形式,特别是对于Python3?

python printing format

94
推荐指数
4
解决办法
8万
查看次数

标签 统计

format ×1

printing ×1

python ×1