Python Program To Check String Has Capital Letter
“How TO Check String Has Capital Letter Using Python” is used to check uppercase letters available or not in a particular string. Here we are going to cover a number of methods to check capital latter in strings using a python program.
01. Example
Using isupper() function with For loop.
- Initialize String.
- Set a falg value False.
- Check with isupper() function.
# String initializing string = 'Zeroones' # printing original string print("The input string : " + str(string)) flag = False for element in string: # checking for capital letter and Decide Flag Value if element.isupper(): flag = True break # printing output print("String Contain Capital Letter: " + str(flag))
Output:
The input string : Zeroones
String Contain Capital Letter: True
02. Example
Using isupper() and any() functions.
- Initialize String.
- Check isupper() with any() function.
- Print Result.
# initializing string string = 'Zeroones' # printing original string print("The input string : " + str(string)) # Using any() and isupper() function flag = any(element.isupper() for element in string) # printing result print("String Contain Capital Letter: " + str(flag))
Output:
The input string : Zeroones
String Contain Capital Letter: True
03. Example
Using Letters String() and Foor Loop.
- Initialize String.
- Set Flag value.
- Use for loop to decide flag value.
- Print Result.
# initializing string string = 'Zeroones' letters="ABCDEFGHIJKLMNOPQRSTUVWXYZ" # printing original string print("The input string : " + str(string)) flag = False for element in string: if(element in letters): flag = True break # print result print("String Contain Capital Letter: " + str(flag))
Output:
The input string : Zeroones
String Contain Capital Letter: True