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 Closures
Python issubclass()
Python Variables, Constants and Literals
Python Package
Python Set intersection()
Python String center()
Python divmod()
Python slice()
Python Program to Find Hash of File
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python String isupper()
Python Program to Check Armstrong Number
Python Program to Display Powers of 2 Using Anonymous Function
Python Program to Find the Factors of a Number
Python Iterators
Check If a String Is Numeric in Java
Python Program to Check Whether a String is Palindrome or Not
Python Program to Find Numbers Divisible by Another Number
Python Program to Check if a Number is Odd or Even
Python String strip()
Python String rindex()
Python Program to Slice Lists
Python String rfind()
Python Operator Overloading
Python List
Python Program to Trim Whitespace From a String
Python min()
Python Input, Output and Import
Python Program to Access Index of a List Using for Loop
Python Program to Create Pyramid Patterns
Python Program to Illustrate Different Set Operations
Python Program to Convert String to Datetime