擅长:python、mysql、java
<p>在<code>.join()</code>之前出现的任何内容都在括号内的每个元素中间隔:</p>
<pre><code>'---'.join( "..." ) ==> .---.---.
</code></pre>
<p>您是join的<strong>链接调用</strong>,因此每个结果都被间隔到以下join部分:</p>
<pre><code>phrase = "Don't panic!"
plist = list(phrase)
np1 = ''.join(plist[1:3]) # with itermediate results, see output
np2 = np1.join(plist[5:3:-1]) # the slice is "t ", it puts 'on' between " " and "t"
np3 = np2.join(plist[-5:-7:-1]) # the slice is "ap", it puts " ont" between
# 'a' and 'p'
print(np1,np2,np3 ) # ('on', ' ont', 'a ontp')
</code></pre>
<p>替代解决方案:</p>
<pre><code>print( phrase[1:3]+phrase[5:3:-1]+phrase[7:5:-1] )
</code></pre>
<p>提供:</p>
<pre><code>on tap
</code></pre>