Skip to content
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
PPLi8787
Python
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
Python
/
strings
/
upper.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
22 lines (18 loc) · 532 Bytes
master
Breadcrumbs
Python
/
strings
/
upper.py
Copy path
Top
File metadata and controls
Code
Blame
22 lines (18 loc) · 532 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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()
You can’t perform that action at this time.