What is the numpy.char.startswith() function in Python?

Overview

The char.startswith() function in Python returns an array of Boolean values which is True where the string element in an input array of string starts with prefix. Otherwise, it returns False.

Syntax

char.startswith(a, prefix, start=0, end=None)
Syntax for the char.startswith() function

Parameters

The char.startswith()function takes the following parameter values:

  • a: An input array of strings.
  • prefix : A string representing the prefix to be searched for.
  • start, end: The optional start means that the test will begin at that position while an optional end means stopping the comparison at that position.

Return value

The char.startswith() function returns an array of Boolean values with the same shape as the input array a.

Code

import numpy as np
# creating input arrays
myarray1 = np.array(
["Theo",
"Theophilus",
"The",
"Theology"])
# printing the input array
print(myarray1)
# implementing the char.startswith()
# function on both arrays to see if they are equal
print(np.char.startswith
(myarray1,
"Theo",
start=0,
end=None))
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources