<blockquote>
<p><strong>Possible Duplicate:</strong><br/>
<a href="https://stackoverflow.com/questions/36901/what-does-and-do-for-python-parameters">What does ** and * do for python parameters?</a><br/>
<a href="https://stackoverflow.com/questions/287085/what-does-args-and-kwargs-mean">What does *args and **kwargs mean?</a> </p>
</blockquote>
<p>简单程序:</p>
<pre><code>storyFormat = """
Once upon a time, deep in an ancient jungle,
there lived a {animal}. This {animal}
liked to eat {food}, but the jungle had
very little {food} to offer. One day, an
explorer found the {animal} and discovered
it liked {food}. The explorer took the
{animal} back to {city}, where it could
eat as much {food} as it wanted. However,
the {animal} became homesick, so the
explorer brought it back to the jungle,
leaving a large supply of {food}.
The End
"""
def tellStory():
userPicks = dict()
addPick('animal', userPicks)
addPick('food', userPicks)
addPick('city', userPicks)
story = storyFormat.format(**userPicks)
print(story)
def addPick(cue, dictionary):
'''Prompt for a user response using the cue string,
and place the cue-response pair in the dictionary.
'''
prompt = 'Enter an example for ' + cue + ': '
response = input(prompt).strip() # 3.2 Windows bug fix
dictionary[cue] = response
tellStory()
input("Press Enter to end the program.")
</code></pre>
<p>关注这一行:</p>
<pre><code> story = storyFormat.format(**userPicks)
</code></pre>
<p>什么是<code>**</code>的意思?为什么不直接通过一个简单的<code>userPicks</code>?</p>