709. To Lower Case
🟩 Easy
Question
Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.
Example 1:
Input: "Hello"
Output: "hello"
Example 2:
Input: "here"
Output: "here"
Example 3:
Input: "LOVELY"
Output: "lovely"
Code
def toLowerCase(self, str: str) -> str:
lower = ""
for c in str:
lower += chr(ord(c) + 32) if ord(c) <= 90 and ord(c) >= 65 else c
return lower
Last updated
Was this helpful?