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 Convert Celsius To Fahrenheit
Python Program to Add Two Numbers
Python slice()
Python Multiple Inheritance
Python Custom Exceptions
Python Program to Count the Number of Each Vowel
Python Program to Copy a File
Python range()
Python Program to Compute all the Permutation of the String
Case-Insensitive String Matching in Java
Python Closures
Python pow()
Python List append()
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Program to Represent enum
Python Program to Remove Punctuations From a String
Python Program to Convert Kilometers to Miles
Python Program to Count the Number of Digits Present In a Number
Converting a Stack Trace to a String in Java
Python List
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Set copy()
Python String format_map()
Python Program to Safely Create a Nested Directory
Python String encode()
Python Program to Convert Two Lists Into a Dictionary
Python chr()
Converting a List to String in Java
Python Program to Find Numbers Divisible by Another Number
Python type()
Python List insert()
String Initialization in Java