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.
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:
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.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics