How to capitalize first letter in Python
In this article, we will discuss certain ways to capitalize the first letter of a string in Python.
Method 1: Using capitalize()
The capitalize() method converts the first character of a string to capital (uppercase) letter.
string = "pythonpoint" print("Original string: "+str(string)) final = string.capitalize() print("After capitalizing: "+str(final))
Output:
Original string: pythonpoint After capitalizing: Pythonpoint
Method 2: Using string slicing and upper()
The upper() method upper cases the characters provided to it.
string = "pythonpoint" print("Original string: "+str(string)) final = string[0].upper() + string[1:] print("After capitalizing: "+str(final))
Output:
Original string: pythonpoint After capitalizing: Pythonpoint
Subscribe
Login
Please login to comment
0 Discussion