代码及异常信息如下所示:
>>> "{ }:计算机{ }的CPU使用率是{ }%".format("2017-6-27","python",10)
Traceback (most recent call last):File "<pyshell#1>", line 1, in <module>
"{ }:计算机{ }的CPU使用率是{ }%".format("2017-6-27","python",10)
KeyError: ' '
百度了好久发现没有相似的回答,后来发现原来是keyError没有注意到,format在使用时“{ }”内要么没有空格,要么有序号,不能总有空格。
之前还怀疑是python3.6不支持不带序号的format形式,笑哭