2020-09-03 15:11:23 +01:00
|
|
|
def capitalize(sentence: str) -> str:
|
|
|
|
|
"""
|
2023-10-26 13:55:08 +05:30
|
|
|
Capitalizes the first letter of a sentence or word.
|
|
|
|
|
|
2020-09-03 15:11:23 +01:00
|
|
|
>>> capitalize("hello world")
|
|
|
|
|
'Hello world'
|
|
|
|
|
>>> capitalize("123 hello world")
|
|
|
|
|
'123 hello world'
|
|
|
|
|
>>> capitalize(" hello world")
|
|
|
|
|
' hello world'
|
|
|
|
|
>>> capitalize("a")
|
|
|
|
|
'A'
|
|
|
|
|
>>> capitalize("")
|
|
|
|
|
''
|
|
|
|
|
"""
|
|
|
|
|
if not sentence:
|
2020-09-10 16:31:26 +08:00
|
|
|
return ""
|
2023-10-26 13:55:08 +05:30
|
|
|
|
|
|
|
|
# Capitalize the first character if it's a lowercase letter
|
|
|
|
|
# Concatenate the capitalized character with the rest of the string
|
2025-08-24 13:37:39 +03:30
|
|
|
return sentence[0].upper() + sentence[1:]
|
2020-09-03 15:11:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
from doctest import testmod
|
|
|
|
|
|
|
|
|
|
testmod()
|