Skip to content

Commit c22d862

Browse files
Update capitalize.py
1 parent d219a3c commit c22d862

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

strings/capitalize.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@ def capitalize(sentence: str) -> str:
1616
if not sentence:
1717
return ""
1818

19-
# Get the first character of the sentence
20-
first_char = sentence[0]
21-
# Check if the first character is a lowercase letter
22-
if "a" <= first_char <= "z":
23-
# Convert the lowercase letter to uppercase using ASCII value
24-
first_char = chr(ord(first_char) - 32)
25-
# Return the capitalized first character concatenated with the rest of the sentence
26-
return first_char + sentence[1:]
19+
# Capitalize the first character if it's a lowercase letter
20+
# Concatenate the capitalized character with the rest of the string
21+
return sentence[0].upper() + sentence[1:]
2722

2823

2924
if __name__ == "__main__":

0 commit comments

Comments
 (0)