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 Display the multiplication Table
Python Variables, Constants and Literals
Python String maketrans()
Python Program to Remove Duplicate Element From a List
Python Set clear()
Python Set intersection_update()
Python time Module
Python Program to Check If Two Strings are Anagram
Deep Learning with Python - Francois Chollet
Python Dictionary keys()
Python Program to Print all Prime Numbers in an Interval
Python Iterators
Introduction to Scientific Programming with Python - Joakim Sundnes
Python Program to Find the Sum of Natural Numbers
Python Program to Parse a String to a Float or Int
Python eval()
Python File I/O Operation
Machine Learning with Python for everyone - Mark E.Fenner
Python String isdecimal()
Python if...else Statement
Python globals()
Encode a String to UTF-8 in Java
Python Closures
Python Program to Find the Factors of a Number
Python Program to Compute all the Permutation of the String
Python round()
Python delattr()
JavaScript Eval: run a code string
Python Program to Delete an Element From a Dictionary
Python open()
Python Program to Capitalize the First Character of a String
Python max()