VOOZH about

URL: https://www.geeksforgeeks.org/python/python-numpy-np-char-endswith-method/

⇱ np.char.endswith() method - Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

np.char.endswith() method - Python

Last Updated : 29 Sep, 2025

The np.char.endswith() method is used to check whether each string in a NumPy array ends with a specified substring.

For Example: This example checks whether each string in a 1D array ends with the letter "s".


Output
Array: ['cats' 'dogs' 'fish']
Result: [ True True False]

Explanation:

  • "cats" and "dogs" end with "s" -> True
  • "fish" does not end with "s" -> False

Syntax

np.char.endswith(a, suffix)

Parameters:

  • a: array_like of str -> Input array of strings.
  • suffix: str -> Substring to check at the end of each string.

Return Value: ndarray of bool -> Boolean array indicating whether each string ends with the given substring.

Examples

Example 1: This example checks if strings in a 1D array end with "ks".


Output
[ True False True]

Example 2: This example checks if strings in the array end with the digit "1".


Output
[ True False False True]

Example 3: This example shows that the method is case-sensitive.


Output
[ True False True]
Comment