當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python numpy char.endswith用法及代碼示例

本文簡要介紹 python 語言中 numpy.char.endswith 的用法。

用法:

char.endswith(a, suffix, start=0, end=None)

返回一個布爾數組,即True其中字符串元素在a以。。結束後綴, 否則False.

逐元素調用 str.endswith

參數

a 類似 str 或 unicode 的 數組
suffix str
start, end 整數,可選

使用可選開始,從該位置開始測試。使用可選結束,在該位置停止比較。

返回

out ndarray

輸出一個布爾數組。

例子

>>> s = np.array(['foo', 'bar'])
>>> s[0] = 'foo'
>>> s[1] = 'bar'
>>> s
array(['foo', 'bar'], dtype='<U3')
>>> np.char.endswith(s, 'ar')
array([False,  True])
>>> np.char.endswith(s, 'a', start=1, end=2)
array([False,  True])

相關用法


注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.char.endswith。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。