为了更好地理解文档,我开始用python风格的伪代码编写
str.format
。
然而,这是不正确的。
class str:
def format(self, *args, **kwargs):
# do something with args
# after processing args, do the following:
for key in kwargs:
x = "{"+key+"}"
ostr = kwargs[key].join(self.split(x))
return ostr # output string
我们如何编辑这个 psython 风格的伪代码,使其符合文档中描述的行为?