Change language

Python | Lowercase first character of a string

|

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

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:" + 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 

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method