Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Python String isalpha() Method
Next article icon

isupper() method in Python checks if all the alphabetic characters in a string are uppercase. If the string contains at least one alphabetic character and all of them are uppercase, the method returnsTrue. Otherwise, it returnsFalse.

Let's understand this with the help of an example:

Python
s="GEEKSFORGEEKS"print(s.isupper())

Output
True

Explanation:

  • The string 's' contains only uppercase alphabetic characters.
  • Therefore, theisupper() method returnsTrue.
  • This method helps us verify that all characters intended to be uppercase are correctly formatted.

Syntax of method

string.isupper()

Parameters

  • Theisupper() method does not take any parameters.

Return Type

  • ReturnsTrue if all alphabetic characters in the string are uppercase.
  • ReturnsFalse if the string contains lowercase letters or non-alphabetic characters.

Examples of method

Checking a string with all uppercase letters

Let’s examine a case where the string is entirely uppercase, we can use this to validate input when uppercase formatting is required, such as for acronyms or constants.

Python
s1="PYTHON"print(s1.isupper())

Output
True

Explanation:

  • The strings1 is made up entirely of uppercase alphabetic characters.
  • The method returnsTrue, confirming that all alphabetic characters ins1 are uppercase.

Checking a string with mixed case letters

This method is helpful when we want to ensure that no lowercase letters are present in a string.

Python
s2="PyThOn"print(s2.isupper())

Output
False

Explanation:

  • The strings2 contains both uppercase (P,T,O) and lowercase (y,h,n) characters.
  • As a result,isupper() returnsFalse.

Checking a string with non-alphabetic characters

Let’s check howisupper() behaves when the string contains numbers or special characters.

Python
s3="123#@!"print(s3.isupper())

Output
False

Explanation:

  • The strings3 contains only non-alphabetic characters (numbers and special symbols).
  • Since there are no uppercase alphabetic characters,isupper() returnsFalse.

String with spaces and uppercase letters

This method is useful when validating input strings with uppercase letters and spaces, such as titles or banners.

Python
s4="PYTHON IS FUN"print(s4.isupper())

Output
True

Explanation:

  • The strings4 contains uppercase alphabetic characters and spaces.
  • Spaces are non-alphabetic characters and do not affect the result.
  • The method returnsTrue, confirming that all alphabetic characters ins4 are uppercase.

5. An empty string

This is useful when we want to ensure that we’re working with meaningful input before applying further processing.

Python
s5=""print(s5.isupper())

Output
False

Explanation:

  • The strings5 is empty and does not contain any characters.
  • Theisupper() method returnsFalse since there are no uppercase alphabetic characters to validate.

Improve

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp