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.
# 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)) |
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.
# 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))) |
The original string is : GeeksforGeeks The string after lowercasing initial character : geeksforGeeks
Recommended Posts:
- Python | Return lowercase characters from given string
- Python | Frequency of each character in String
- Python program for removing i-th character from a string
- Ways to remove i'th character from string in Python
- Python | Split string on Kth Occurrence of Character
- Python | Count occurrences of a character in string
- Python | Find position of a character in given string
- Python program to find occurrence to each character in given string
- Python | Construct string from character frequency tuple
- Python | Check order of character in string using OrderedDict( )
- Python Regex | Program to accept string ending with alphanumeric character
- Generate two output strings depending upon occurrence of character in input string in Python
- Python | Convert string List to Nested Character List
- Python | Insert character after every character pair
- Count occurrences of a sub-string with one variable character
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.


