isupper()

my_str.isupper()
Returns True if all chars in a string are upper case letters , otherwise rturns False
my_str='WELCOME TO PYTHON'
print(my_str.isupper())      # Output is True 

my_str='Welcome to Python'
print(my_str.isupper())      # Output is False

my_str='Welcome To Python'
print(my_str.isupper())      # Output is False

my_str='WELCOME 100'
print(my_str.isupper())      # Output is True

Handling Mixed Characters

isupper() returns True even if the string contains numbers or special characters, as long as all alphabetic characters are uppercase:

my_str = 'HELLO123!@'
print(my_str.isupper())  # Output: True

Use Case: Validating Form Input

In form submissions, you might require the input to be in uppercase. isupper() helps validate that:

user_input = "PASSWORD"
if user_input.isupper():
    print("Valid input.")

Checking Empty Strings

isupper() returns False for empty strings because there are no characters to check:

empty_str = ''
print(empty_str.isupper())  # Output: False

Use Case: Cleaning Up Data

In data processing, you might want to filter out strings that aren't uppercase:

data = ["HELLO", "World", "PYTHON", "code"]
upper_data = [word for word in data if word.isupper()]
print(upper_data)  # Output: ['HELLO', 'PYTHON']

Mixed Case Strings

Strings with mixed cases will return False:

print("HelloWorld".isupper())  # Output: False

Checking Strings with Spaces

isupper() ignores spaces, and checks only alphabetic characters:

text = 'HELLO WORLD'
print(text.isupper())  # Output: True

Handling Unicode Characters

Unicode characters are also checked, and the method still works for non-ASCII characters:

text = 'PYTHON 你好'
print(text.isupper())  # Output: True

Combining with Other String Methods

Use isupper() with other string methods for flexible validation:

text = 'password'
print(text.upper().isupper())  # Output: True
All String methods


Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer