forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlower.py
26 lines (21 loc) · 657 Bytes
/
lower.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
deflower(word: str) ->str:
"""
Will convert the entire string to lowercase letters
>>> lower("wow")
'wow'
>>> lower("HellZo")
'hellzo'
>>> lower("WHAT")
'what'
>>> lower("wh[]32")
'wh[]32'
>>> lower("whAT")
'what'
"""
# Converting to ASCII value, obtaining the integer representation
# and checking to see if the character is a capital letter.
# If it is a capital letter, it is shifted by 32, making it a lowercase letter.
return"".join(chr(ord(char) +32) if"A"<=char<="Z"elsecharforcharinword)
if__name__=="__main__":
fromdoctestimporttestmod
testmod()