Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions strings/capitalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ def capitalize(sentence: str) -> str:
>>> capitalize("")
''
"""
if not sentence:
return ""

# Capitalize the first character if it's a lowercase letter
# Concatenate the capitalized character with the rest of the string
return sentence[0].upper() + sentence[1:]
# Slicing keeps this safe for empty strings.
return sentence[:1].upper() + sentence[1:]


if __name__ == "__main__":
Expand Down