Att String Istitle
## Python String istitle() Method
The `istitle()` method is a built-in Python string method used to determine whether a string is cased in title case.
In a title-cased string, every word must begin with an uppercase character, and all remaining characters in each word must be lowercase.
---
## Description
The `istitle()` method checks whether all cased words in the string start with an uppercase letter followed only by lowercase letters.
* It returns `True` if the string meets the title case criteria and contains at least one cased character.
* It returns `False` if any word starts with a lowercase letter, contains uppercase letters in non-initial positions, or if the string contains no cased characters (e.g., only numbers or symbols).
---
## Syntax
The syntax for the `istitle()` method is as follows:
```python
str.istitle()
```
### Parameters
* **None**: This method does not accept any parameters.
### Return Value
* **`True`**: If the string is a title-cased string.
* **`False`**: If the string is not title-cased, or if it is empty/contains no cased characters.
---
## Code Examples
### Example 1: Basic Usage
The following example demonstrates how `istitle()` evaluates different string formats:
```python
# Title-cased string
str1 = "This Is String Example...Wow!!!"
print(str1.istitle()) # Output: True
# Non-title-cased string (contains lowercase initials)
str2 = "This is string example....wow!!!"
print(str2.istitle()) # Output: False
```
### Example 2: Handling Numbers, Symbols, and Whitespace
Non-alphabetic characters (like numbers, punctuation, and spaces) are ignored by `istitle()`. However, the first alphabetic character following any non-alphabetic character must be uppercase.
```python
# Numbers and symbols are ignored; the words themselves are title-cased
str3 = "10 Reasons Why Python Is Great!"
print(str3.istitle()) # Output: True
# The word 'python' starts with a lowercase letter after a number
str4 = "10 reasons why python is great!"
print(str4.istitle()) # Output: False
# Empty strings or strings with only numbers/symbols return False
str5 = "12345 @#$%"
print(str5.istitle()) # Output: False
```
---
## Important Considerations
1. **Case-Insensitive Characters**: Characters without case mapping (such as numbers, punctuation marks, and whitespace) are ignored during the check.
2. **Consecutive Uppercase Letters**: If a word contains consecutive uppercase letters (e.g., `"HTML"` or `"Python"`), `istitle()` will return `False` because characters after the first letter must be lowercase.
3. **Empty Strings**: Calling `"".istitle()` returns `False` because there must be at least one cased character present in the string to evaluate.
4. **Relationship with `title()`**: You can convert any string to title case using the `title()` method. Consequently, `str.title().istitle()` will generally return `True` (provided the string contains at least one cased character).
YouTip