Method # 1: Using string slicing + lower()
This task can be easily accomplished using the lowercase method that provides lowercase characters provided to it and delimiting can be used to add the remainder of the line after the first lowercase character.
# Python3 code to demonstrate how it works # Lowercase first character of line # Using lower () + slicing lines # initialization string test_str = "GeeksforGeeks" # print original line c ode> print ( "The original string is:" + str (test_str)) # Using lower () + slicing lines # Lowercase first character of line res = test_str [ 0 ]. lower () + test_str [ 1 :] # print result print ( "The string after lowercasing initial character:" + co de> str (res)) |
Output:
The original string is: Python.Engineering The string after lowercasing initial character: geeksforGeeks
Method # 2: Using lambda + line slice + lower()
A lambda function recipe must be added if we need to perform the task of handling None values or empty strings, and it becomes necessary to handle edge cases.
# Python3 code to demonstrate how it works # Lowercase first character of line # Using lower () + slicing lines + lambda # initialization string test_str < / code> = "GeeksforGeeks" # print the original line print ( "The original string is:" + str (test_str)) # Usage lower () + line splitting + lambda # Lowercase first character of the line res = lambda test_str: test_str [: 1 ]. lower () + test_str [ 1 : ] if test_str else ’ ’ # print result print ( "The string after lowercasing initial character:" + str (res (test_str))) |
Output:
The original string is: Python.Engineering The string after lowercasing initial character: geeksforGeeks
Python | Lowercase first character of a string Python functions: Questions
Python | Lowercase first character of a string String Variables: Questions