Welcome folks today in this blog post we will be capitalize
first character of String in python. All the full source code of the application is given below.
Capitalize Using Upper() Method
Now we will use the upper()
method to capitalize first character of string.
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# Python3 code to demonstrate working of # Initial character upper case # Using upper() + string slicing # initializing string test_str = "codingshiksha" # printing original string print("The original string is : " + str(test_str)) # Using upper() + string slicing # Initial character upper case res = test_str[0].upper() + test_str[1:] # printing result print("The string after uppercasing initial character : " + str(res)) |
Capitalize First Character Using capitalize
method
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# Python3 code to demonstrate working of # Initial character upper case # Using capitalize() + string slicing # initializing string test_str = "geeksforgeeks" # printing original string print("The original string is : " + str(test_str)) # Using capitalize() + string slicing # Initial character upper case res = test_str.capitalize() # printing result print("The string after uppercasing initial character : " + str(res)) |
Now if you execute the python script by typing the below command
python app.py