Python/strings/upper.py
Saurabh Mahapatra f968dda5e9
Updated Comments on upper.py (#10442)
* Updated Comments on upper.py

* Update upper.py

* Update upper.py

---------

Co-authored-by: Christian Clauss <cclauss@me.com>
2023-10-14 15:02:37 -04:00

23 lines
532 B
Python

def upper(word: str) -> str:
"""
Convert an entire string to ASCII uppercase letters by looking for lowercase ASCII
letters and subtracting 32 from their integer representation to get the uppercase
letter.
>>> upper("wow")
'WOW'
>>> upper("Hello")
'HELLO'
>>> upper("WHAT")
'WHAT'
>>> upper("wh[]32")
'WH[]32'
"""
return "".join(chr(ord(char) - 32) if "a" <= char <= "z" else char for char in word)
if __name__ == "__main__":
from doctest import testmod
testmod()