In the previous article, we have discussed Python String istitle() Method Examples
isupper() Method in Python:
The string isupper() method determines whether all characters in a string are uppercased.
Syntax:
string.isupper()
Parameters: This function has no parameters.
Return Value:
The isupper() method gives:
- True if all of the characters in a string are uppercase.
- If any of the characters in a string are lowercase, this function returns false.
Examples:
Example1:
Input:
Given string = 'Welcome To Python-programs' Given string = '1234 HELLO ALL @' Given string = 'GOOD MORNING BTECHGEEKS'
Output:
The given string = Welcome To Python-programs Checking if the given string has all uppercase characters or not = False The given string = 1234 HELLO ALL @ Checking if the given string has all uppercase characters or not = True The given string = GOOD MORNING BTECHGEEKS Checking if the given string has all uppercase characters or not = True
Example2:
Input:
Given string = 'HELLO THIS IS BTECH_GEEKS' Given string = 'ThIs IS a PYThon learning PLATform' Given string = '#### HELLO EVERYONE ##%%$12346'
Output:
The given string = HELLO THIS IS BTECH_GEEKS Checking if the given string has all uppercase characters or not = True The given string = ThIs IS a PYThon learning PLATform Checking if the given string has all uppercase characters or not = False The given string = #### HELLO EVERYONE ##%%$12346 Checking if the given string has all uppercase characters or not = True
String isupper() Method Examples in Python
Method #1: Using Built-in Functions (Static Input)
Approach:
- Give the string as static input and store it in a variable.
- Apply isupper() function to the given string that returns true if all of the characters in a given string are uppercase. If any of the characters in a string are lowercase, this function returns false.
- Store it in another variable.
- Print the above-given String.
- Print the result after checking if the given string has all uppercase characters or not.
- Similarly, do the same for other strings and print the result.
- The Exit of Program.
Below is the implementation:
# Give the string as static input and store it in a variable. gvn_strng1 = 'Welcome To Python-programs' # Apply isupper() function to the given string that returns true if all # of the characters in a given string are uppercase. If any of the characters # in a string are lowercase, this function returns false. # Store it in another variable. rslt_1 = gvn_strng1.isupper() # Print the above-given String. print("The given string = ", gvn_strng1) # Print the result after checking if the given string has all uppercase # characters or not. print("Checking if the given string has all uppercase characters or not = ", rslt_1) # Similarly, do the same for other strings and print the result. gvn_strng2 = '1234 HELLO ALL @' rslt_2 = gvn_strng2.isupper() print("The given string = ", gvn_strng2) print("Checking if the given string has all uppercase characters or not = ", rslt_2) gvn_strng3 = 'GOOD MORNING BTECHGEEKS' rslt_3 = gvn_strng3.isupper() print("The given string = ", gvn_strng3) print("Checking if the given string has all uppercase characters or not = ", rslt_3)
Output:
The given string = Welcome To Python-programs Checking if the given string has all uppercase characters or not = False The given string = 1234 HELLO ALL @ Checking if the given string has all uppercase characters or not = True The given string = GOOD MORNING BTECHGEEKS Checking if the given string has all uppercase characters or not = True
Method #2: Using Built-in Functions (User Input)
Approach:
- Give the string as user input using the input() function and store it in a variable.
- Apply isupper() function to the given string that returns true if all of the characters in a given string are uppercase. If any of the characters in a string are lowercase, this function returns false.
- Store it in another variable.
- Print the above-given String.
- Print the result after checking if the given string has all uppercase characters or not.
- Similarly, do the same for other strings and print the result.
- The Exit of Program.
Below is the implementation:
# Give the string as user input using the input() function and store it in a variable. gvn_strng1 = input("Enter some Random String = ") # Apply isupper() function to the given string that returns true if all # of the characters in a given string are uppercase. If any of the characters # in a string are lowercase, this function returns false. # Store it in another variable. rslt_1 = gvn_strng1.isupper() # Print the above-given String. print("The given string = ", gvn_strng1) # Print the result after checking if the given string has all uppercase # characters or not. print("Checking if the given string has all uppercase characters or not = ", rslt_1) # Similarly, do the same for other strings and print the result. gvn_strng2 = input("Enter some Random String = ") rslt_2 = gvn_strng2.isupper() print("The given string = ", gvn_strng2) print("Checking if the given string has all uppercase characters or not = ", rslt_2) gvn_strng3 = input("Enter some Random String = ") rslt_3 = gvn_strng3.isupper() print("The given string = ", gvn_strng3) print("Checking if the given string has all uppercase characters or not = ", rslt_3)
Output:
Enter some Random String = HELLO THIS IS BTECH_GEEKS The given string = HELLO THIS IS BTECH_GEEKS Checking if the given string has all uppercase characters or not = True Enter some Random String = THis is A PYTHON LEARNING PLATform The given string = THis is A PYTHON LEARNING PLATform Checking if the given string has all uppercase characters or not = False Enter some Random String = #### HELLO EVERYONE #@@#5678 The given string = #### HELLO EVERYONE #@@#5678 Checking if the given string has all uppercase characters or not = True
Go through our tutorial and learn about various Python String Method Examples and learn how to apply the knowledge while dealing with strings.