擅长:python、mysql、java
<p>我使用了切片和replace()函数。replace()简单。。。替换!你知道吗</p>
<pre><code>string = 'initialword_content'
content = string[12:] # You mentioned that intialword will always be the same length, so I used slicing.
content = content.replace('_', ' ')
</code></pre>
<p>例如:</p>
<pre><code>>>> string = 'elephantone_con_ten_t' # elephantone was the first thing I thought of xD
>>> content = string[12:]
>>> content
... con_ten_t
>>> content = content.replace('_', ' ')
>>> content
... con ten t
</code></pre>
<p>但是,如果您还想在其他地方引用“elephantone”,请执行以下操作:</p>
<pre><code>>>> string = 'elephantone_con_ten_t'
>>> l = string.split('_', 1) # This will only strip the string ONCE from the left.
>>> l[0]
... 'elephantone'
>>> l[1].replace('_', ' ')
... 'con ten t'
</code></pre>