LeetCode刷题(python)——709. 转换成小写字母

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kobe_academy/article/details/88256198

题目描述:

实现函数 ToLowerCase(),该函数接收一个字符串参数 str,并将该字符串中的大写字母转换成小写字母,之后返回新的字符串。

示例 1:

输入: "Hello"
输出: "hello"

示例 2:

输入: "here"
输出: "here"

示例 3:

输入: "LOVELY"
输出: "lovely"

解题思路:

 I have nothing to say........2333333333

代码实现:

class Solution:
    def toLowerCase(self, str: str) -> str:
        str1 = ''
        for x in str:
            if ord('A') <= ord(x) <= ord('Z'):
                str1 += chr(ord(x) + 32)
            else:
                str1 += x
        return str1

                                                        关注我的公众号免费获取海量python学习资料!!!

猜你喜欢

转载自blog.csdn.net/kobe_academy/article/details/88256198