python String capitalize() Method
The capitalize() function returns a new copy of the original string and converts the first character of the string to a capital letter, while all other characters in the string are lowercase.
How to formulate it like this:
string_name. capitalize()
Argument: The capitalize() function takes no argument.
The capitalize() function returns a new string in which the first character is a capital letter, and the rest of the string is a lowercase letter.
Example:
txt = "learn python with ahmad obaid"
cap = txt.capitalize()
print(cap)
The output will be:
Learn python with ahmad obaid
The capitalize() function returns a new copy of the string and does not modify the original string
Example:
string = "i love python"
print(string)
print(string.capitalize())
The output will be:
i love python
I love python
External sources:
Built-in functions - official Python documentation
If you have any questions or concerns, leave them in the comments
Tags
Python Python String string methods python string capitalize python
Share page
About author
Ahmed Obaid
Hello, I am Ahmed Obaid, an Egyptian Arabic programmer. I would like to put my experiences learning Python on this site So that it will be a reference for you and me as well.
Sign up to leave a comment