擅长:python、mysql、java
<p>正如其他人所指出的,字符串是不可变的。但是,可以使用slice操作符的细节来缩短版本:</p>
<pre><code>genes_new = genes[:p] + "0" + genes[p+1:]
# another way is to use this kind of generator expression
''.join(x[i] if i != p else '0' for i in xrange(len(x)))
</code></pre>