

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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.
For example
>>> s = "my name" >>> s.capitalize() 'My name'
You can also manually achieve this by string slicing.
For example
>>> 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.
For example
>>> s = "my name" >>> s.title() 'My Name'
- Related Questions & Answers
- string capitalize() in Python
- Write a Java program to capitalize each word in the string?
- How to capitalize the first letter of each word in a string using JavaScript?
- Java Program to Capitalize the first character of each word in a String
- Capitalize letter in a string in order and create an array to store - JavaScript
- 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?
- Capitalize a word and replace spaces with underscore - JavaScript?
Advertisements