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 Decorators
Python Sets
Python frozenset()
Python String isdigit()
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python String rfind()
Converting a Stack Trace to a String in Java
Python List pop()
Python sleep()
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Program to Find HCF or GCD
Python Directory and Files Management
Python super()
Array to String Conversions
Python Type Conversion and Type Casting
Python Program to Trim Whitespace From a String
Python Dictionary fromkeys()
Python Program to Check Prime Number
Python sum()
Python Program to Display Calendar
Most commonly used String methods in Java
Python time Module
Python Get Current time
Python Program to Iterate Over Dictionaries Using for Loop
Python Program to Display Powers of 2 Using Anonymous Function
Python property()
Jackson – Marshall String to JsonNode
Python Program to Create Pyramid Patterns
Python Function Arguments
APIs in Node.js vs Python - A Comparison
Python Program to Convert Two Lists Into a Dictionary
Python String swapcase()