我正在阅读 Python 2.7 教程,并且正在查看以下语句的输出:
def cheeseshop(kind, *arguments, **keywords):
print "-- Do you have any", kind, "?"
print "-- I'm sorry, we're all out of", kind
for arg in arguments:
print arg
print "-" * 40
keys = sorted(keywords.keys())
for kw in keys:
print kw, ":", keywords[kw]
所以,如果我这样调用程序:
cheeseshop("Cheddar", "No.", "Seriously?",
Shopkeeper="Michael Palin",
Client="John Cleese")
它输出:
Do you have any Cheddar?
I'm sorry, we're all out of Cheddar
No.
Seriously?
--------------------------------------
Client: John Cleese
Shopkeeper: Michael Palin
这是对的。
如果我将该打印语句更改为print keywords
,我会得到以下表示:
{'Shopkeeper': 'Ryan Lambert', 'Client': 'John Cleese'}
我对打印如何keywords[kw]
返回一个名称感到有点困惑,而keywords
没有。