Will convert the entire string to lowercase letters >>> lower("wow") 'wow' >>> lower("HellZo") 'hellzo' >>> lower("WHAT") 'what' >>> lower("wh[]32") 'wh[]32' >>> lower("whAT") 'what'
(word: str)
| 1 | def lower(word: str) -> str: |
| 2 | """ |
| 3 | Will convert the entire string to lowercase letters |
| 4 | |
| 5 | >>> lower("wow") |
| 6 | 'wow' |
| 7 | >>> lower("HellZo") |
| 8 | 'hellzo' |
| 9 | >>> lower("WHAT") |
| 10 | 'what' |
| 11 | >>> lower("wh[]32") |
| 12 | 'wh[]32' |
| 13 | >>> lower("whAT") |
| 14 | 'what' |
| 15 | """ |
| 16 | |
| 17 | # Converting to ASCII value, obtaining the integer representation |
| 18 | # and checking to see if the character is a capital letter. |
| 19 | # If it is a capital letter, it is shifted by 32, making it a lowercase letter. |
| 20 | return "".join(chr(ord(char) + 32) if "A" <= char <= "Z" else char for char in word) |
| 21 | |
| 22 | |
| 23 | if __name__ == "__main__": |
nothing calls this directly
no outgoing calls
no test coverage detected