A catalog needs quick presentation-style capitalization for labels entered in inconsistent case.
What You Need to Understand
The str.title() method returns a new string in which each word begins with an uppercase letter and the remaining cased letters are lowercase. It does not change its original string. The method detects word boundaries using its own character rules, not a human language dictionary.
When to Use It
A catalog needs quick presentation-style capitalization for labels entered in inconsistent case.
Step-by-Step Python Example
label = "wIRELESS mOUSE and USB ADAPTER"
print(label.title())
print(label)
How the Example Works
The new value is Wireless Mouse And Usb Adapter; the original remains unchanged. Acronyms such as USB will not necessarily be preserved.
Example Output
Wireless Mouse And Usb Adapter
wIRELESS mOUSE and USB ADAPTER
Quick Start Guide
A Second Example
Compare this smaller variation with the main example, then experiment with your own values.
heading = "quick start guide"
formatted_heading = heading.title()
print(formatted_heading)
Important Behavior and Edge Cases
Apostrophes and non-letter boundaries can produce awkward names such as They'Re. Do not use title() as an authoritative person-name formatter.
Try It Yourself
Test "o'connor" and decide whether the displayed result is acceptable for a real customer name.
Common Beginner Mistakes
- Apostrophes and non-letter boundaries can produce awkward names such as
They'Re. Do not usetitle()as an authoritative person-name formatter. - Applying a string method before defining whether text is intended for display, comparison, parsing, or input validation.
Key Takeaways
- The
str.title()method returns a new string in which each word begins with an uppercase letter and the remaining cased letters are lowercase. - The new value is
Wireless Mouse And Usb Adapter; the original remains unchanged. - Apostrophes and non-letter boundaries can produce awkward names such as
They'Re.