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 object()
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Program to Measure the Elapsed Time in Python
Python Program to Check Armstrong Number
Python Program to Iterate Through Two Lists in Parallel
Python Dictionary
Python String ljust()
Python Set symmetric_difference()
Python Program to Compute all the Permutation of the String
How to get current date and time in Python?
Python print()
Python Program to Check the File Size
Python filter()
Python classmethod()
Python round()
Java – String to Reader
Python Program to Copy a File
Python Dictionary fromkeys()
Python String isalnum()
Python Package
Encode a String to UTF-8 in Java
Python String index()
Python Program to Delete an Element From a Dictionary
Deep Learning from Scratch - Building with Python form First Principles - Seth Weidman
Python String isalpha()
Python Program to Convert Kilometers to Miles
Python format()
Python Program to Append to a File
Python String rindex()
Python next()
Map to String Conversion in Java
Python List Comprehension