Capitalize the First Character of a String in Python Using upper()

Python Program to Capitalize the First Character of a String Using upper() Function

#Capitalize the First Character of a String Using string slicing() and upper() method in python

s = "python"
print("Original string: " +s)
# slicing technique to extract the string's first letter in this method. We then used the upper() string manipulation method to convert it into uppercase.
result = s[0].upper() + s[1:]

print("After capitalizing the first letter: " +result)

Output:

Original string: python
After capitalizing the first letter: Python

About The Author

Leave a Reply