Python Program To Check String Has Capital Letter

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.

  1. Initialize String.
  2. Set a falg value False.
  3. 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.

  1. Initialize String.
  2. Check isupper() with any() function.
  3. 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.

  1. Initialize String.
  2. Set Flag value.
  3. Use for loop to decide flag value.
  4. 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

Leave a comment