Numpy字符串操作 |开始()函数
numpy.core.defchararray.startswith()函数返回一个布尔数组,该数组为 True,其中字符串元素以前缀开头,否则为 False。
Syntax : numpy.core.defchararray.startswith(arr, prefix, start = 0, end = None)
Parameters :
arr : [array-like of str or unicode] Array-like of str.
prefix : [str] Input string.
start, end : [int, optional] With optional start, test beginning at that position. With optional end, stop comparing at that position.
Return : [ndarray] Return the array of booleans.
代码#1:
Python3
# Python program explaining
# numpy.char.startswith() function
# importing numpy as geek
import numpy as geek
arr = "GeeksforGeeks - A computer science portal"
prefix = 'Geeks'
gfg = geek.char.startswith(arr, prefix, start = 0, end = None)
print (gfg)
Python3
# Python program explaining
# numpy.char.startswith() function
# importing numpy as geek
import numpy as geek
arr = "GeeksforGeeks - A computer science portal"
prefix = 'None'
gfg = geek.char.startswith(arr, prefix, start = 0, end = None)
print (gfg)
输出 :
True
代码#2:
Python3
# Python program explaining
# numpy.char.startswith() function
# importing numpy as geek
import numpy as geek
arr = "GeeksforGeeks - A computer science portal"
prefix = 'None'
gfg = geek.char.startswith(arr, prefix, start = 0, end = None)
print (gfg)
输出 :
False