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

ParameterTypeDescription
xarray_like (StringDType, bytes_, or str_ dtype)Input array containing string elements.
outndarray, None, or tuple of ndarray and None, optionalOptional output array where the result is stored. If None, a new array is created.
wherearray_like, optionalBoolean mask specifying which elements to check. Elements where where=False retain their original value.
castingstr, optionalDefines the casting behavior when computing the function.
orderstr, optionalMemory layout order of the output array.
dtypedata-type, optionalDefines the data type of the output array.
subokbool, optionalDetermines 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]