w3resource

Python: Check whether lowercase letters exist in a string

Python Basic: Exercise-128 with Solution

Write a Python program to check whether lowercase letters exist in a string.

Pictorial Presentation:

Check whether lowercase letters exist in a string

Sample Solution-1:

Python Code:

str1 = 'A8238i823acdeOUEI'
print(any(c.islower() for c in str1))

Sample Output:

True 

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:


Sample Solution-2:

Python Code:

def lower_case_str(text):
   ctr = 0
   for char in text:
       if(ord(char) >= 97 and ord(char) <= 122):
           ctr = ctr + 1
   if (ctr>0):
       return True
str1 = 'A8238i823acdeOUEI'
print("Original string:",str1)
print("Lowercase letters exist in the said string: ",lower_case_str(str1))
str1 = 'PYTHON'
print("\nOriginal string:",str1)
print("Lowercase letters exist in the said string: ",lower_case_str(str1))
str1 = 'javascript'
print("\nOriginal string:",str1)
print("Lowercase letters exist in the said string: ",lower_case_str(str1))

Sample Output:

Original string: A8238i823acdeOUEI
Lowercase letters exist in the said string:  True

Original string: PYTHON
Lowercase letters exist in the said string:  None

Original string: javascript
Lowercase letters exist in the said string:  True

Flowchart:

Flowchart: Check whether lowercase letters exist in a string.

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:


Check if all input alphabets are small:

Python Code:

def lower_case_str(text):
   if text.islower():
       return True
   return False
print("Check if all input alphabets are small!")
str1 = 'A8238i823acdeOUEI'
print("\nOriginal string:",str1)
print("Lowercase letters exist in the said string: ",lower_case_str(str1))
str1 = 'PYTHON'
print("\nOriginal string:",str1)
print("Lowercase letters exist in the said string: ",lower_case_str(str1))
str1 = 'javascript'
print("\nOriginal string:",str1)
print("Lowercase letters exist in the said string: ",lower_case_str(str1))

Sample Output:

Check if all input alphabets are small!

Original string: A8238i823acdeOUEI
Lowercase letters exist in the said string:  False

Original string: PYTHON
Lowercase letters exist in the said string:  False

Original string: javascript
Lowercase letters exist in the said string:  True

Flowchart:

Flowchart: Check whether lowercase letters exist in a string.

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:


Python Code Editor:

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to check whether an integer fits in 64 bits.
Next: Write a Python program to add leading zeroes to a string.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Try-catch-else construct:

try:
  foo() 
except Exception: 
  print("Exception occured")
else:
  print("Exception didnt occur")
finally:
  print("Always gets here")