Table of Contents
In Python, the capitalize() method converts first character of a string to uppercase letter and lowercases all other characters, if any.
The syntax of capitalize()
is:
string.capitalize()
1. capitalize() Parameter
The capitalize()
function doesn’t take any parameter.
2. Return Value from capitalize()
The capitalize()
function returns a string with the first letter capitalized and all other characters lowercased. It doesn’t modify the original string.
3. Example 1: Capitalize a Sentence
string = "python is AWesome." capitalized_string = string.capitalize() print('Old String: ', string) print('Capitalized String:', capitalized_string)
Output
Old String: python is AWesome Capitalized String: Python is awesome
4. Example 2: Non-alphabetic First Character
string = "+ is an operator." new_string = string.capitalize() print('Old String:', string) print('New String:', new_string)
Output
Old String: + is an operator. New String: + is an operator.
Related posts:
CharSequence vs. String in Java
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python bool()
Check If a String Is Numeric in Java
Python String index()
Python Directory and Files Management
Python Set discard()
Python Program to Get the Class Name of an Instance
Python String isspace()
Python hasattr()
Python Program to Get the File Name From the File Path
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python Program to Sort Words in Alphabetic Order
Python timestamp to datetime and vice-versa
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python Exception Handling Using try, except and finally statement
Python List clear()
String Processing with Apache Commons Lang 3
Python Program to Get the Last Element of the List
Python List copy()
How to Remove the Last Character of a String?
Python Program to Find Sum of Natural Numbers Using Recursion
Python Generators
Python String isupper()
Generate a String
Python Program to Remove Duplicate Element From a List
Python Tuple
Python List sort()
Python int()
Python oct()
Python min()