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 String isidentifier()
Java – Generate Random String
Python Set union()
Python Program to Count the Number of Digits Present In a Number
Python Program to Copy a File
Python Program to Display Fibonacci Sequence Using Recursion
Python Program to Extract Extension From the File Name
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python Program to Convert Celsius To Fahrenheit
Python Program to Solve Quadratic Equation
Python ord()
Python complex()
Python Dictionary values()
Python map()
Python classmethod()
Python Program to Represent enum
Python Program to Find ASCII Value of Character
Python Data Analytics with Pandas, NumPy and Matplotlib - Fabio Nelli
Java InputStream to String
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Java String to InputStream
Python Modules
Python Program to Create a Countdown Timer
Python Program to Compute all the Permutation of the String
How to Get Started With Python?
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python break and continue
Python Functions
Python Program to Check Whether a String is Palindrome or Not
Machine Learning with Python for everyone - Mark E.Fenner
Python Program to Get a Substring of a String
Generate a String