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:
Array to String Conversions
Python String isspace()
Python Dictionary copy()
Python Program to Check Whether a String is Palindrome or Not
Python Machine Learning Eqution Reference - Sebastian Raschka
Python object()
Python Set intersection()
Python Decorators
Python String rpartition()
Python Matrices and NumPy Arrays
Python while Loop
Python String ljust()
Python List remove()
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Map to String Conversion in Java
Python isinstance()
Python vars()
Python String endswith()
Python Program to Convert Celsius To Fahrenheit
Python Program to Find All File with .txt Extension Present Inside a Directory
Python time Module
Python delattr()
Python Dictionary update()
Python frozenset()
Python eval()
Python Program to Print the Fibonacci sequence
Python String rfind()
String Set Queries
Python Functions
Java String to InputStream
Python String lower()
Python List count()