Python 3 Script to Capitalize First Character of String Using Upper() and Capitalize() Methods Full Tutorial For Beginners

Python 3 Script to Capitalize First Character of String Using Upper() and Capitalize() Methods Full Tutorial For Beginners

 

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

 

# 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))

 

See also  Python 3 Kivy Instagram API Automate Liking User Posts Bot GUI Desktop App Full Project For Beginners

 

 

 

Capitalize First Character Using capitalize method

 

app.py

 

# 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))

 

See also  Python 3 Tkinter Checkers Board Strategy Game GUI Desktop App Full Project For Beginners

 

Now if you execute the python script by typing the below command

 

python app.py

 

 

Leave a Reply