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:
APIs in Node.js vs Python - A Comparison
Python String count()
Python Program to Find the Factorial of a Number
Python oct()
Python String replace()
Converting String to Stream of chars
Python Program to Reverse a Number
Python Program to Randomly Select an Element From the List
Python Dictionary popitem()
Python chr()
Python help()
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido
Python Program to Make a Flattened List from Nested List
Python set()
Python String title()
Python Global Keyword
Python String rsplit()
Python float()
Python String encode()
Python max()
Python String format_map()
Python Operators
Reading an HTTP Response Body as a String in Java
Python input()
Python str()
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python Program to Print Colored Text to the Terminal
Python staticmethod()
Python Function Arguments
Python Program to Add Two Numbers
Python Dictionary fromkeys()
Python delattr()