1 Star 0 Fork 324

codingsills/Python

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
lower.py 657 Bytes
一键复制 编辑 原始数据 按行查看 历史
Saurabh Mahapatra 提交于 2023-10-13 23:55 +08:00 . Modified comments on lower.py (#10369)
def lower(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" else char for char in word)
if __name__ == "__main__":
from doctest import testmod
testmod()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/codingsills/Python.git
git@gitee.com:codingsills/Python.git
codingsills
Python
Python
master

搜索帮助