

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to check if a string contains only upper case letters in Python?
We can check if a string contains only upper case letters using 2 methods. First is using method isupper().
example
print( 'Hello world'.isupper()) print('HELLO'.isupper())
Output
False True
You can also use regexes for the same result. For matching only uppercase, we can call the re.match(regex, string) using the regex: "^[A-Z]+$".
example
import re print(bool(re.match('^[A-Z]+$', '123aAbc')) print(bool(re.match('^[A-Z]+$', 'ABC'))
Output
False True
- Related Questions & Answers
- How to check if a string contains only lower case letters in Python?
- How to check if a string contains only whitespace letters in Python?
- Check if the String contains only unicode letters in Java
- How to check if a Python string contains only digits?
- How to find If a given String contains only letters in Java?
- Check if the String contains only unicode letters and space in Java
- Check if the String contains only unicode letters or digits in Java
- How to check if a character is upper-case in Python?
- How to check if a string only contains certain characters in Python?
- Check if the String contains only unicode letters, digits or space in Java
- How to check if a string contains only decimal characters?
- How to check if a unicode string contains only numeric characters in Python?
- Method to check if a String contains a sub string ignoring case in Java
- How to check if a String contains another String in a case insensitive manner in Java?
- Python Program to check if String contains only Defined Characters using Regex
Advertisements