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 Make a Simple Calculator
Python float()
Python Program to Find Sum of Natural Numbers Using Recursion
Python Set remove()
Python compile()
Python String strip()
Java – Generate Random String
Python List remove()
Python Program to Shuffle Deck of Cards
Python String partition()
Python Program to Display Powers of 2 Using Anonymous Function
Python sum()
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python Program to Count the Number of Occurrence of a Character in String
Python String rstrip()
Python bin()
Python callable()
Python Program to Sort Words in Alphabetic Order
Python Shallow Copy and Deep Copy
Python memoryview()
Python String replace()
Python Global, Local and Nonlocal variables
Python Machine Learning - Sebastian Raschka
Python Set update()
Python Set add()
Python Program to Iterate Through Two Lists in Parallel
Python Set clear()
Convert char to String in Java
Python Program to Copy a File
Python Program to Find the Factors of a Number
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Program to Make a Flattened List from Nested List