Skip to content
Related Articles
Numpy string operations | startswith() function
• Last Updated : 29 Aug, 2020

numpy.core.defchararray.startswith() function returns a boolean array which is True where the string element in starts with prefix, otherwise 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.

Code #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)`

Output :

True

Code #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)`

Output :

False

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up