String First Letter Capitalization in Python
In Python, you can capitalize the first letter of a string using string method str.capitalize()
.
Capitalizing the first letter of a string using 'str.capitalize()' method
1. Create a variable named str_variable
and assign string value "python is a Programming Language."
to the variable.
2. Apply the capitalize()
method to the string variable str_variable
. This method capitalizes the first letter of the string and converts all other characters to lowercase. Store the result in a new variable called cap_variable
.
Please take a closer look at the following example:
Example of using capitalize() method
Output of the above example
Python is a programming language.