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

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / How to Check if Character is Uppercase in Python

How to Check if Character is Uppercase in Python

February 9, 2022 Leave a Comment

In Python, we can check if a character is uppercase by checking if the letter is equal to the letter after applying the Python upper() function.

def checkCharUpper(x):
    return x == x.upper()

print(checkCharUpper("a"))
print(checkCharUpper("A"))

#Output:
False
True

When processing strings in a program, it can be useful to know which letters are uppercase and which characters are lowercase. Using Python, we can easily check if a character is uppercase with the help of the Python upper() function.

To check if a letter is uppercase, we just need to check if that letter is equal to that letter after applying the upper() function.

Below is a Python function which will check if a character is uppercase.

def checkCharUpper(x):
    return x == x.upper()

print(checkCharUpper("a"))
print(checkCharUpper("A"))

#Output:
False
True

How to Check if a Letter is Lowercase in Python

We can also check if a character is lowercase in Python very easily.

To check if a letter is lowercase in Python, we can adjust our function that we defined above to use the Python lower() function instead of the upper() function.

Below is a Python function which will check if a character is lowercase.

def checkCharLower(x):
    return x == x.lower()

print(checkCharLower("a"))
print(checkCharLower("A"))

#Output:
True
False

Hopefully this article has been useful for you to learn how to check if a character is uppercase in Python.

Other Articles You'll Also Like:

  • 1.  Writing a Table Faster to Word Document Using python-docx
  • 2.  Get Random Value from Dictionary in Python
  • 3.  Change Python Turtle Shape Fill Color with fillcolor() Function
  • 4.  Get Quarter from Date in pandas DataFrame
  • 5.  Python Check if Dictionary Value is Empty
  • 6.  Python os.sep – Create Operating System Path Seperator Character
  • 7.  Using Python to Read File Word by Word
  • 8.  pandas max – Find Maximum Value of Series or DataFrame
  • 9.  How to Rotate a List in Python
  • 10.  Find All Pythagorean Triples in a Range using Python

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

x