Capitalizes the first letter of a sentence or word. >>> capitalize("hello world") 'Hello world' >>> capitalize("123 hello world") '123 hello world' >>> capitalize(" hello world") ' hello world' >>> capitalize("a") 'A' >>> capitalize("") ''
(sentence: str)
| 1 | def capitalize(sentence: str) -> str: |
| 2 | """ |
| 3 | Capitalizes the first letter of a sentence or word. |
| 4 | |
| 5 | >>> capitalize("hello world") |
| 6 | 'Hello world' |
| 7 | >>> capitalize("123 hello world") |
| 8 | '123 hello world' |
| 9 | >>> capitalize(" hello world") |
| 10 | ' hello world' |
| 11 | >>> capitalize("a") |
| 12 | 'A' |
| 13 | >>> capitalize("") |
| 14 | '' |
| 15 | """ |
| 16 | if not sentence: |
| 17 | return "" |
| 18 | |
| 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:] |
| 22 | |
| 23 | |
| 24 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected