-1
請解釋Python如何評估這個字符串,以便可以設置一個字的值大於字符串中的另一個字的值?如何b> n。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
發現返回的位置,那麼你真的比較數字。 http://docs.python.org/2/library/string.html#string.find – sachleen
請參閱[這個問題](http://stackoverflow.com/questions/4806911/string-comparison-technique-used-by- python) – eebbesen
嘗試用_'調用你的函數當樂隊演奏lambada'_時,薩克斯演奏者彈出錯誤音符。 – pillmuncher