我遇到了Python string.find()
方法的問題。它似乎這樣工作很好:python string.find()方法不接受關鍵字參數
p = mystr.find('id=')
它正確地返回第一個匹配。
然而,當我嘗試使用格式與其他參數,如:
p2 = mystr.find('id=', start=p+3)
據報道說:find() not take keyword arguments
我不知道是怎麼回事。
我遇到了Python string.find()
方法的問題。它似乎這樣工作很好:python string.find()方法不接受關鍵字參數
p = mystr.find('id=')
它正確地返回第一個匹配。
然而,當我嘗試使用格式與其他參數,如:
p2 = mystr.find('id=', start=p+3)
據報道說:find() not take keyword arguments
我不知道是怎麼回事。
不要使用start
,直接給p+3
這樣
p2 = mystr.find('id=', p+3)
例如,
p = "id=id=1"
i = p.find("id=")
print p.find("id=", i + 3)
將打印3
我沒發現哪裏出了問題,但我發現這個問題的解決方案:-)
只需使用find()會以另一種方式,如:
import string as st
p2 = st.find(mystr, 'id=', start=p+3)
的偉大工程:-)
此功能已棄用(http://docs.python.org/2/library/string.html#deprecated-string-functions)。 –
謝謝,@Robᵩ但我不敢苟同。我問了這個問題,因爲沒有任何其他問題的直接解決方案。這個問題的答案更有用,對嗎? –
*旁白*:您的標題不正確。 ['string.find()'](http://docs.python.org/2/library/string.html#string.find)**不會**取關鍵字參數,因爲你自己的答案表明。正如問題指出的那樣,['str.find()'](http://docs.python.org/2/library/stdtypes.html#str.find)**不會**取關鍵字參數。 –
謝謝你指出。 –