擅长:python、mysql、java
<p><a href="https://docs.python.org/3/library/stdtypes.html#str.replace" rel="nofollow noreferrer">str.replace</a>通过将旧的替换为新的方式返回字符串的新副本,并且您不保存它,所以只需始终保存新副本并执行下一个<code>replace</code>操作</p>
<blockquote>
<p>Return a copy of the string with all occurrences of substring old replaced by new</p>
</blockquote>
<pre><code>alist = ['bla', 'blblblbl', 'asasa', 'blblblblblb']
astring = 'bla lalala lvlvl lblblbl asasa'
for i in alist:
if i in astring:
astring = astring.replace(i,'True') # True lalala lvlvl lblblbl True
print(astring)
</code></pre>