Python | Lowercase first character of String

The problem of capitalizing a string is quite common and has been discussed many times. But sometimes, we might have a problem like this in which we need to convert the first character of string to lowercase. Let’s discuss certain ways in which this can be performed.

Method #1 : Using string slicing + lower()
This task can easily be performed using the lower method which lowercases the characters provided to it and slicing can be used to add the remaining string after the lowercase first character.

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 code to demonstrate working of
# Lowercase first character of String
# Using lower() + string slicing
  
# initializing string 
test_str = "GeeksforGeeks"
  
# printing original string 
print("The original string is : " + str(test_str))
  
# Using lower() + string slicing
# Lowercase first character of String
res = test_str[0].lower() + test_str[1:]
  
# printing result 
print("The string after lowercasing initial character : " + str(res))

chevron_right


Output :

The original string is : GeeksforGeeks
The string after lowercasing initial character : geeksforGeeks

 

Method #2 : Using lambda + string slicing + lower()
The recipe of lambda function has to be added if we need to perform the task of handling None values or empty strings as well, and this becomes essential to handle edge cases.

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 code to demonstrate working of
# Lowercase first character of String
# Using lower() + string slicing + lambda
  
# initializing string 
test_str = "GeeksforGeeks"
  
# printing original string 
print("The original string is : " + str(test_str))
  
# Using lower() + string slicing + lambda
# Lowercase first character of String
res = lambda test_str: test_str[:1].lower() +
               test_str[1:] if test_str else ''
  
# printing result 
print("The string after lowercasing initial character : " + str(res(test_str)))

chevron_right


Output :

The original string is : GeeksforGeeks
The string after lowercasing initial character : geeksforGeeks


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.