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:
Python reversed()
Python str()
Python Set isdisjoint()
Python Set issuperset()
Python Program to Convert String to Datetime
Python String splitlines()
Python Object Oriented Programming
Python Program to Check the File Size
Python Tuple index()
Java String Conversions
Python callable()
Python time Module
Python Deep Learning Cookbook - Indra den Bakker
Python Program to Display Calendar
String Initialization in Java
Python Program to Sort Words in Alphabetic Order
Python List count()
Python Program to Catch Multiple Exceptions in One Line
Python String format()
Python Program to Get the File Name From the File Path
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python help()
Python complex()
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python sleep()
Python enumerate()
Python Program to Add Two Matrices
Python Program to Check Prime Number
Python String index()
Python Program to Get File Creation and Modification Date
Python Program to Convert Decimal to Binary Using Recursion
Python property()