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 Create Pyramid Patterns
Python String isidentifier()
Python Tuple count()
Generate a String
String Processing with Apache Commons Lang 3
Python locals()
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python Functions
Python __import__()
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python String isspace()
Python Program to Find Armstrong Number in an Interval
Python chr()
Python Program to Randomly Select an Element From the List
Python Shallow Copy and Deep Copy
Python Dictionary fromkeys()
Python staticmethod()
Python abs()
Python sum()
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python frozenset()
Python Dictionary
Python String zfill()
Python next()
Python List clear()
Convert String to Byte Array and Reverse in Java
Most commonly used String methods in Java
Python Program to Differentiate Between del, remove, and pop on a List
Python globals()
Python Type Conversion and Type Casting
Converting a Stack Trace to a String in Java
Python Program to Reverse a Number