Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if all characters of a string are uppercase

Tags:

Say I have a string that can contain different characters:

e.g. word = "UPPER£CASe"

How would I test the string to see if all the characters are uppercase and no other punctuation, numbers, lowercase letters etc?

like image 636
ffgghhffgghh Avatar asked Nov 24 '15 00:11

ffgghhffgghh


People also ask

How do you check if all letters in a string are uppercase?

To check if a string is in uppercase, we can use the isupper() method. isupper() checks whether every case-based character in a string is in uppercase, and returns a True or False value depending on the outcome.

How do you check if a character in a string is uppercase Java?

To check whether a character is in Uppercase or not in Java, use the Character. isUpperCase() method.

How do you check if a character in a string is uppercase Python?

To check if a character is upper-case, we can simply use isupper() function call on the said character.

How do you check if a character in a string is uppercase in C?

C isupper() The isupper() function checks whether a character is an uppercase alphabet (A-Z) or not.


1 Answers

You should use str.isupper() and str.isalpha() function.

Eg.

is_all_uppercase = word.isupper() and word.isalpha() 

According to the docs:

S.isupper() -> bool 

Return True if all cased characters in S are uppercase and there is at least one cased character in S, False otherwise.

like image 182
Yash Mehrotra Avatar answered Sep 22 '22 08:09

Yash Mehrotra