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 open()
Python Program to Safely Create a Nested Directory
Convert char to String in Java
Deep Learning with Python - Francois Chollet
Python File I/O Operation
Python Program to Print the Fibonacci sequence
Python Program to Print Hello world!
Python Set issubset()
Python String isidentifier()
Python String isdecimal()
Python datetime
Python Program to Display Powers of 2 Using Anonymous Function
Python Modules
Python List
Python Program to Sort Words in Alphabetic Order
Python String split()
Python Program to Remove Punctuations From a String
Python Program to Sort a Dictionary by Value
Python ascii()
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Python str()
Python Program to Check If a String Is a Number (Float)
Python timestamp to datetime and vice-versa
Python callable()
Python Program to Count the Occurrence of an Item in a List
Deep Learning in Python - LazyProgrammer
Python Program to Get the Full Path of the Current Working Directory
Python getattr()
Python Program to Illustrate Different Set Operations
Java Program to Permute All Letters of an Input String
Python Program to Count the Number of Each Vowel