We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Strings
- String Validators
- Discussions
String Validators
String Validators
+ 0 comments s = input() anum = False abetic = False digit = False lower = False upper = False for i in s: if i.isalnum(): anum = True if i.isalpha(): abetic = True if i.isdigit(): digit = True if i.islower(): lower = True if i.isupper(): upper = True print(anum) print(abetic) print(digit) print(lower) print(upper)
+ 0 comments s = input() first=False second=False third=False fourth=False fifth=False for i in s: first = i.isalnum() or first second =i.isalpha() or second third = i.isdigit() or third fourth = i.islower() or fourth fifth = i.isupper() or fifth print(first) print(second) print(third) print(fourth) print(fifth)
+ 0 comments Yet another way
def string_validation(string): checks = (str.isalnum, str.isalpha, str.isdigit, str.islower, str.isupper) for check in checks: yield any([check(char) for char in string]) if __name__ == '__main__': string = input() for validation in string_validation(string): print(validation)
+ 1 comment s =input() print(any([x.isalnum() for x in s])) print(any([x.isalpha() for x in s])) print(any([x.isdigit() for x in s])) print(any([x.islower() for x in s])) print(any([x.isupper() for x in s]))
+ 0 comments Solution using list comprehension.
if __name__ == '__main__': s = input() print("True" if True in [True for x in s if x.isalnum()] else "False") print("True" if True in [True for x in s if x.isalpha()] else "False") print("True" if True in [True for x in s if x.isdigit()] else "False") print("True" if True in [True for x in s if x.islower()] else "False") print("True" if True in [True for x in s if x.isupper()] else "False")
Load more conversations
Sort 1620 Discussions, By:
Please Login in order to post a comment