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

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

示例 1:

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

示例 2:

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

示例 3:

输入: "LOVELY"
输出: "lovely"
class Solution:
    def toLowerCase(self, str):
        """
        :type str: str
        :rtype: str
        """
        n=len(str)
        temp=list(str)
        for i in range(n):
            if temp[i]>='A' and temp[i]<='Z':
                x= ord(temp[i])+32
                temp[i]=chr(x)
        return ''.join(temp)

猜你喜欢

转载自blog.csdn.net/qq_27060423/article/details/82432031