我刚开始学习Python,并一直关注Google Python类。在串演习之一,有这样的代码:Python字符串切片中的+是什么意思?
def not_bad(s):
n = s.find('not')
b = s.find('bad')
if n != -1 and b != -1 and b > n:
s = s[:n] + 'good' + s[b+3:]
return s
我想知道什么的S [B + 3]表示,因为这是我第一次碰到+串片内。
切片没什么特别的。分片中的“b + 3”意味着“b + 3”意味着其他任何地方的相同。 – BrenBarn