Introduction
In Python, we can capitalize the first letter of a string using various methods. In this challenge, you are required to write a function that capitalizes the first letter of a given string.
This tutorial is from open-source community. Access the source code
In Python, we can capitalize the first letter of a string using various methods. In this challenge, you are required to write a function that capitalizes the first letter of a given string.
Write a Python function called capitalize_string(s, lower_rest=False)
that takes a string as an argument and returns a new string with the first letter capitalized. The function should have an optional parameter lower_rest
which, if set to True
, converts the rest of the string to lowercase.
capitalize_string('hello world') ## 'Hello world'
capitalize_string('hello world', True) ## 'Hello world'
In this challenge, you have learned how to capitalize the first letter of a string in Python. You can use the capitalize()
method or write a custom function to achieve the same result.