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 Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python Program to Solve Quadratic Equation
Python hex()
Python String lower()
Python set()
Python Set isdisjoint()
Python 3 for Absolute Beginners - Tim Hall & J.P Stacey
Python format()
Python type()
Python delattr()
Introduction to Scientific Programming with Python - Joakim Sundnes
Python Program to Find the Square Root
Python String isnumeric()
Python Program to Create a Countdown Timer
Python tuple()
Java – Generate Random String
Python String isupper()
CharSequence vs. String in Java
Python Program to Compute the Power of a Number
Python String rsplit()
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Program to Convert Two Lists Into a Dictionary
Python Program to Illustrate Different Set Operations
Python Program to Print Hello world!
Python datetime
Python Program to Check Armstrong Number
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python Program to Get the Last Element of the List
Python Set intersection_update()
Python String islower()
Python Sets
Python Program to Create Pyramid Patterns