擅长:python、mysql、java
<p>这里有一种使用<code>str.format</code>的方法。你知道吗</p>
<pre><code>favorite_languages = {'jen': ['python','ruby'],
'sarah': ['c'],
'edward': ['ruby','C++'],
'phil': ['python']}
for name, language in favorite_languages.items():
print("{0}'s favorite language{1} {2}".format(name.title(),
's are' if len(language)>1 else ' is', ' and '.join(language)))
</code></pre>
<p>结果:</p>
<pre><code>Jen's favorite languages are python and ruby
Sarah's favorite language is c
Edward's favorite languages are ruby and C++
Phil's favorite language is python
</code></pre>