w3resource

NumPy String: numpy.char.istitle() function

numpy.char.istitle() function

The numpy.char.istitle() function checks whether each string element of an array has its first letter capitalized (i.e., is in title case) and the remaining letters are in lowercase.

The function is useful to filter strings that have a specific title case pattern in a given dataset.

Syntax:

numpy.char.istitle(a)

Parameter:

Name Description Required /
Optional
a: array_like of str or unicode Input an array_like of string or unicode Required

Return value:

array of bools

Example: Check if a string starts with a capital letter in Python using numpy.char.istitle()

>>> import numpy as np
>>> x = np.char.istitle('the quick brown fox')
>>> x
array(False)

In the above code, the input string 'the quick brown fox' does not start with a titlecase letter, so the output is False.

Pictorial Presentation:

NumPy String operation: istitle() function

Example: numpy.char.istitle() for checking titlecased strings

>>> import numpy as np
>>> y = np.char.istitle('The Quick Brown Fox')
>>> y
array(True)

In the above code, the numpy.char.istitle() function is applied to "The Quick Brown Fox" and the string satisfies the criteria, and hence the function returns True.

Pictorial Presentation:

NumPy String operation: istitle() function

Python - NumPy Code Editor:

Previous: isspace()
Next: isupper()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/numpy/string-operations/istitle.php