转换成小写,请问我这个哪里错了?
s为字符串,将大写转换成小写class Solution:
def toLowerCase(self, s: str) -> str:
lst=list(s)
for i in lst:
if i>'A'and i<'Z':
i=chr(ord(i)+32)
return ''.join(lst)
结果啥都没变,为啥?哪里错了 class Solution :
def toLowerCase(self , s : str) -> str:
lst = list(s)
for i in range(len(lst)):
if lst >= 'A' and lst <= 'Z':
lst = chr(ord(lst) + 32)
return '' . join(lst)
a = Solution()
print(a . toLowerCase('ABC')) 本帖最后由 傻眼貓咪 于 2021-12-3 20:07 编辑
class Solution:
def toLowerCase(self, s: str) -> str:
arr = list(s)
for n, i in enumerate(arr):
arr = chr(ord(i) + 32)
return ''.join(arr)
A = Solution()
print(A.toLowerCase("ABCDEF")) 你虽然i变了,但是lst没变啊
class Solution:
def toLowerCase(self, s: str) -> str:
lst=list(s)
lst1 = []
for i in lst:
if i>'A'and i<'Z':
i=chr(ord(i)+32)
lst1.append(i)
return ''.join(lst1)
谢谢各位大侠~
页:
[1]