MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / upper

Function upper

strings/upper.py:1–16  ·  view source on GitHub ↗

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(

(word: str)

Source from the content-addressed store, hash-verified

1def upper(word: str) -> str:
2 """
3 Convert an entire string to ASCII uppercase letters by looking for lowercase ASCII
4 letters and subtracting 32 from their integer representation to get the uppercase
5 letter.
6
7 >>> upper("wow")
8 'WOW'
9 >>> upper("Hello")
10 'HELLO'
11 >>> upper("WHAT")
12 'WHAT'
13 >>> upper("wh[]32")
14 'WH[]32'
15 """
16 return "".join(chr(ord(char) - 32) if "a" <= char <= "z" else char for char in word)
17
18
19if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected