mirror of
https://github.com/TheAlgorithms/Python.git
synced 2026-09-29 05:53:07 +08:00
Bumps [actions/upload-pages-artifact](https://github.com/actions/upload-pages-artifact) from 4 to 5. - [Release notes](https://github.com/actions/upload-pages-artifact/releases) - [Commits](https://github.com/actions/upload-pages-artifact/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/upload-pages-artifact dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
27 lines
648 B
Python
27 lines
648 B
Python
def capitalize(sentence: str) -> str:
|
|
"""
|
|
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("")
|
|
''
|
|
"""
|
|
|
|
# Capitalize the first character if it's a lowercase letter
|
|
# Concatenate the capitalized character with the rest of the string
|
|
# Slicing keeps this safe for empty strings.
|
|
return sentence[:1].upper() + sentence[1:]
|
|
|
|
|
|
if __name__ == "__main__":
|
|
from doctest import testmod
|
|
|
|
testmod()
|