- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to capitalize a string in Python?
If you want to just capitalize the first letter of the first word of the string, then you can use the capitalize method from string class.
>>> s = "my name" >>> s.capitalize() 'My name'
You can also manually achieve this by string slicing.
>>> s = "my name" >>> s = s[:1].upper() + s[1:] 'My name'
If you want to capitalize each word of the string, then you should use the title method from the string class.
>>> s = "my name" >>> s.title() 'My Name'
- string capitalize() in Python
- Write a Java program to capitalize each word in the string?
- Java Program to Capitalize the first character of each word in a String
- Python program to capitalize each word's first letter
- Capitalize text with CSS
- How can we capitalize only first letter of a string with the help of MySQL function/s?
- How to reverse a string in Python?
- How to split a string in Python
- Capitalize first letter of a column in Pandas dataframe
- Pandas dataframe capitalize first letter of a column
- How to reverse a string in Python program?
- How to convert a string to dictionary in Python?