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 Functions
Python String encode()
Python Type Conversion and Type Casting
Python Operators
Python Program to Check If a String Is a Number (Float)
Converting a Stack Trace to a String in Java
Python pow()
Python repr()
Deep Learning with Python - Francois Cholletf
Python list()
Python Program to Convert Celsius To Fahrenheit
Python classmethod()
Python Program to Illustrate Different Set Operations
Python Program to Find LCM
Format ZonedDateTime to String
Python Iterators
Python Program to Find the Size (Resolution) of a Image
String Set Queries
Python Program to Sort a Dictionary by Value
Python hash()
Python Program to Safely Create a Nested Directory
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Extract Extension From the File Name
Python Set difference_update()
Convert Character Array to String in Java
Python staticmethod()
Python filter()
How to get current date and time in Python?
Python Namespace and Scope
Python Input, Output and Import
Python Set issubset()
Python issubclass()