NumPy strings.islower()
The numpy.strings.islower() function checks whether all cased characters in each string element of an input array are lowercase.
At least one cased character must be present for it to return True.
Syntax
</>
Copy
numpy.strings.islower(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)
Parameters
| Parameter | Type | Description |
|---|---|---|
x | array_like (StringDType, bytes_, or str_ dtype) | Input array containing string elements. |
out | ndarray, None, or tuple of ndarray and None, optional | Optional output array where the result is stored. If None, a new array is created. |
where | array_like, optional | Boolean mask specifying which elements to check. Elements where where=False retain their original value. |
casting | str, optional | Defines the casting behavior when computing the function. |
order | str, optional | Memory layout order of the output array. |
dtype | data-type, optional | Defines the data type of the output array. |
subok | bool, optional | Determines if subclasses of ndarray are preserved in the output. |
Return Value
Returns a boolean array indicating whether all cased characters in each element are lowercase and at least one cased character is present. If the input is a scalar, a scalar boolean value is returned.
Examples
1. Checking Lowercase Strings in an Array
We check if each string in an array consists only of lowercase characters.
</>
Copy
import numpy as np
# Define an array of strings
strings = np.array(["hello", "World", "python", "123"])
# Check which strings are completely lowercase
result = np.strings.islower(strings)
# Print the results
print("Input strings:", strings)
print("Are they lowercase?", result)
Output:
Input strings: ['hello' 'World' 'python' '123']
Are they lowercase? [ True False True False]
