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 Program to Check If a List is Empty
Python String split()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python if...else Statement
Python bytes()
Python abs()
Machine Learning with Python for everyone - Mark E.Fenner
Python Program to Convert Kilometers to Miles
Python sleep()
Python Program to Compute all the Permutation of the String
Python String maketrans()
Python Program to Get Line Count of a File
Python Program to Check the File Size
Python Program to Find Numbers Divisible by Another Number
Python Program to Find the Factors of a Number
Python String isdigit()
Python List clear()
Python exec()
Python Dictionary get()
Python strftime()
Python Program to Parse a String to a Float or Int
JavaScript Eval: run a code string
Python String encode()
Python Keywords and Identifiers
Intelligent Projects Using Python - Santanu Pattanayak
Python repr()
Split a String in Java
Java – Reader to String
Python Program to Get File Creation and Modification Date
Python String rstrip()
Python globals()
Python Exception Handling Using try, except and finally statement