HackerRank Python: String Validators Solution

Table of Contents

Question

Solution

				
					s = input().strip()

print(any(c.isalnum() for c in s))
print(any(c.isalpha() for c in s))
print(any(c.isdigit() for c in s))
print(any(c.islower() for c in s))
print(any(c.isupper() for c in s))

				
			
  1. The input string s is read from the user.

  2. The first print statement checks if there are any alphanumeric characters in the string. It uses the any function along with a generator expression to iterate over each character in the string and check if it is alphanumeric using the isalnum method.

  3. The second print statement checks if there are any alphabetical characters in the string. It uses a similar approach with the any function and the isalpha method.

  4. The third print statement checks if there are any digits in the string using the isdigit method.

  5. The fourth print statement checks if there are any lowercase characters in the string using the islower method.

  6. The fifth print statement checks if there are any uppercase characters in the string using the isupper method.

  7. Each statement prints either True or False based on the result of the corresponding check.

     

If you find anything wrong in this Solution, feel free to reach us in the comment section.

Sharing Is Caring:

Leave a Comment