w3resource

Python: Lowercase first n characters in a string

Python String: Exercise-47 with Solution

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.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/python-exercises/string/python-data-type-string-exercise-47.php