forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupper.py
22 lines (18 loc) · 532 Bytes
/
upper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
defupper(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"elsecharforcharinword)
if__name__=="__main__":
fromdoctestimporttestmod
testmod()