How to LowerCase a String in Python

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
Code language: Python (python)
"These are some WORDS".lower() # <- How to lowerCase a String # output: these are some words
Code language: Python (python)

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"
Code language: JavaScript (javascript)

Example 2:

Input: s = "here" Output: "here"
Code language: JavaScript (javascript)

Example 3:

Input: s = "LOVELY" Output: "lovely"
Code language: JavaScript (javascript)

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()
Code language: Python (python)
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments