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 Multiply Two Matrices
Python String isprintable()
JavaScript Eval: run a code string
Convert Character Array to String in Java
Python Program to Convert Two Lists Into a Dictionary
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Program to Illustrate Different Set Operations
Python String maketrans()
Java String Conversions
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python Program to Iterate Through Two Lists in Parallel
Python bin()
Python Program to Display Calendar
Python Dictionary get()
Python Program to Make a Flattened List from Nested List
Python pow()
Python Program to Find the Sum of Natural Numbers
Python String rstrip()
Python Sets
Python Program to Display the multiplication Table
CharSequence vs. String in Java
Python Program to Display Powers of 2 Using Anonymous Function
Python Global, Local and Nonlocal variables
Python Program to Compute all the Permutation of the String
Python Dictionary items()
Python Program to Count the Occurrence of an Item in a List
Python min()
Python Objects and Classes
Python globals()
Python sorted()
Python String swapcase()
Python Program to Find Hash of File