w3resource

Python: Lowercase first n characters in a string


Lowercase first n characters of string.

Write a Python program to lowercase the first n characters in a string.

Python String Exercises: Lowercase first n characters in a string

Sample Solution:

Python Code:

# Define a string 'str1'.
str1 = 'W3RESOURCE.COM'

# Convert the first four characters of the string to lowercase and concatenate them with the remaining characters.
# Print the modified string.
print(str1[:4].lower() + str1[4:])

Sample Output:

w3reSOURCE.COM                    

Flowchart:

Flowchart: Lowercase first n characters in a string

Python Code Editor:

Previous: Write a Python program to convert a given string into a list of words.
Next: Write a Python program to swap comma and dot in a string.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.