擅长:python、mysql、java
<p>首先,
return语句不在函数体中。你知道吗</p>
<p>其次,
您需要将列表理解的结果存储到某个变量中。你知道吗</p>
<p>以下代码将起作用:</p>
<pre><code>def censor(text, word):
words = text.split()
result = ''
censored = '*' * len(word)
result=[censored if i == word else i for i in words]
return ' '.join(result)
print(censor("this hack is wack hack", "hack"))
this **** is wack ****
</code></pre>