Python comes with a built-in method on all String
types, by calling lower()
on a String, you can immediately lower the case of that String.
An example to LowerCase a String in Python
words = "These are some WORDS"
words.lower() # <- How to lowerCase a String
# output: these are some words
"These are some WORDS".lower() # <- How to lowerCase a String
# output: these are some words
Now let’s try and see how it may look in a coding challenge:
The challenge
Given a string s
, return the string after replacing every uppercase letter with the same lowercase letter.
Example 1:
Input: s = "Hello"
Output: "hello"
Example 2:
Input: s = "here"
Output: "here"
Example 3:
Input: s = "LOVELY"
Output: "lovely"
Constraints:
1 <= s.length <= 100
s
consists of printable ASCII characters.
Our solution in Python code
class Solution:
def toLowerCase(self, s: str) -> str:
return s.lower()