• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • Home
  • Learn to Code
    • Python
    • JavaScript
  • Code Snippets
    • HTML
    • JavaScript
    • jQuery
    • PHP
    • Python
    • SAS
    • Ruby
  • About
You are here: Home / Python / How to Check if String Contains Lowercase Letters in Python

How to Check if String Contains Lowercase Letters in Python

February 11, 2022 Leave a Comment

In Python, we can check if a string contains lowercase characters by checking each letter to see if that letter is lowercase in a loop.

def checkStrContainsLower(string):
    for x in string:
        if x == x.lower():
            return True
    return False

print(checkStrContainsLower("ALL THE LETTERS ARE UPPERCASE"))
print(checkStrContainsLower("We Have some uppercase Letters in this One."))

#Output:
False
True

When processing strings in a program, it can be useful to know if we have uppercase or lowercase characters. Using Python, we can easily check if string contains lowercase characters with the help of the Python lower() function.

To check if a string contains lowercase, we just need to loop over all letters in the string until we find a letter that is equal to that letter after applying the lower() function.

Below is a Python function which will check if a string contains lowercase characters.

def checkStrContainsLower(string):
    for x in string:
        if x == x.lower():
            return True
    return False

print(checkStrContainsLower("ALL THE LETTERS ARE UPPERCASE"))
print(checkStrContainsLower("We Have some uppercase Letters in this One."))

#Output:
False
True

How to Check if String Contains Uppercase in Python

We can also check if a string contains uppercase characters in Python very easily.

To check if a string contains uppercase letters in Python, we can adjust our function that we defined above to use the Python upper() function, instead of the lower() function.

Below is a Python function which will check if a string contains uppercase characters.

def checkStrContainsUpper(string):
    for x in string:
        if x == x.upper():
            return True
    return False

print(checkStrContainsUpper("all letters here are lowercase"))
print(checkStrContainsUpper("We Have some uppercase Letters in this One."))

#Output:
False
True

Hopefully this article has been useful for you to learn how to check if a string contains lowercase characters in Python.

Other Articles You'll Also Like:

  • 1.  How to Group By Columns and Count Rows in pandas DataFrame
  • 2.  Using Python to Iterate Over Two Lists
  • 3.  Get pandas Series First Element in Python
  • 4.  Using Python to Repeat Characters in String
  • 5.  Get Day Name from Datetime in pandas DataFrame
  • 6.  Date Format YYYYMMDD in Python
  • 7.  Sum Columns Dynamically with pandas in Python
  • 8.  What is the Correct File Extension for Python Files?
  • 9.  Not Equal Operator != in Python
  • 10.  Check if Class is Subclass in Python with issubclass()

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy