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>
This commit is contained in:
Saurabh Mahapatra 2023-10-15 00:32:37 +05:30 committed by GitHub
parent 1969259868
commit f968dda5e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,8 @@
def upper(word: str) -> str: def upper(word: str) -> str:
""" """
Will convert the entire string to uppercase letters 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") >>> upper("wow")
'WOW' 'WOW'
@ -11,10 +13,6 @@ def upper(word: str) -> str:
>>> upper("wh[]32") >>> upper("wh[]32")
'WH[]32' 'WH[]32'
""" """
# Converting to ascii value int value and checking to see if char is a lower letter
# if it is a lowercase letter it is getting shift by 32 which makes it an uppercase
# case letter
return "".join(chr(ord(char) - 32) if "a" <= char <= "z" else char for char in word) return "".join(chr(ord(char) - 32) if "a" <= char <= "z" else char for char in word)