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 List extend()
Python break and continue
Python Program to Check Leap Year
JavaScript Methods of RegExp and String
Python String translate()
Python Machine Learning - Sebastian Raschka
Python Program to Check If Two Strings are Anagram
Python String expandtabs()
String Processing with Apache Commons Lang 3
Python Set symmetric_difference_update()
Python bool()
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python String count()
Python String format()
Python Program to Count the Number of Digits Present In a Number
Python map()
Python Program to Capitalize the First Character of a String
Python super()
Python String isalnum()
Python String rpartition()
Python Program to Check Whether a String is Palindrome or Not
Python print()
Python Program to Safely Create a Nested Directory
Python Program to Sort a Dictionary by Value
Python frozenset()
Python Program to Print all Prime Numbers in an Interval
Python String index()
Python String find()
Python Package
Python pow()
Python @property decorator
Python isinstance()