numpy.strings.index#

strings.index(a, sub, start=0, end=None)[source]#

類似 find,但當找不到子字串時會引發 ValueError

參數:
a類陣列,具有 StringDTypebytes_str_ dtype
sub類陣列,具有 StringDTypebytes_str_ dtype
start, end類陣列,具有任何整數 dtype,可選
回傳:
outndarray

整數的輸出陣列。

另請參閱

find, str.index

範例

>>> import numpy as np
>>> a = np.array(["Computer Science"])
>>> np.strings.index(a, "Science", start=0, end=None)
array([9])