|
| 1 | +# Python has built-in string validation methods for basic data. It can check if a string is composed of alphabetical characters, alphanumeric characters, digits, etc. |
| 2 | + |
| 3 | +# str.isalnum() |
| 4 | +# This method checks if all the characters of a string are alphanumeric (a-z, A-Z and 0-9). |
| 5 | + |
| 6 | +# >>> print 'ab123'.isalnum() |
| 7 | +# True |
| 8 | +# >>> print 'ab123#'.isalnum() |
| 9 | +# False |
| 10 | +# str.isalpha() |
| 11 | +# This method checks if all the characters of a string are alphabetical (a-z and A-Z). |
| 12 | + |
| 13 | +# >>> print 'abcD'.isalpha() |
| 14 | +# True |
| 15 | +# >>> print 'abcd1'.isalpha() |
| 16 | +# False |
| 17 | +# str.isdigit() |
| 18 | +# This method checks if all the characters of a string are digits (0-9). |
| 19 | + |
| 20 | +# >>> print '1234'.isdigit() |
| 21 | +# True |
| 22 | +# >>> print '123edsd'.isdigit() |
| 23 | +# False |
| 24 | +# str.islower() |
| 25 | +# This method checks if all the characters of a string are lowercase characters (a-z). |
| 26 | + |
| 27 | +# >>> print 'abcd123#'.islower() |
| 28 | +# True |
| 29 | +# >>> print 'Abcd123#'.islower() |
| 30 | +# False |
| 31 | +# str.isupper() |
| 32 | +# This method checks if all the characters of a string are uppercase characters (A-Z). |
| 33 | + |
| 34 | +# >>> print 'ABCD123#'.isupper() |
| 35 | +# True |
| 36 | +# >>> print 'Abcd123#'.isupper() |
| 37 | +# False |
| 38 | +# Task |
| 39 | + |
| 40 | +# You are given a string . |
| 41 | +# Your task is to find out if the string contains: alphanumeric characters, alphabetical characters, digits, lowercase and uppercase characters. |
| 42 | + |
| 43 | +# Input Format |
| 44 | + |
| 45 | +# A single line containing a string . |
| 46 | + |
| 47 | +# Constraints |
| 48 | + |
| 49 | + |
| 50 | +# Output Format |
| 51 | + |
| 52 | +# In the first line, print True if has any alphanumeric characters. Otherwise, print False. |
| 53 | +# In the second line, print True if has any alphabetical characters. Otherwise, print False. |
| 54 | +# In the third line, print True if has any digits. Otherwise, print False. |
| 55 | +# In the fourth line, print True if has any lowercase characters. Otherwise, print False. |
| 56 | +# In the fifth line, print True if has any uppercase characters. Otherwise, print False. |
| 57 | + |
| 58 | +# Sample Input |
| 59 | + |
| 60 | +# qA2 |
| 61 | +# Sample Output |
| 62 | + |
| 63 | +# True |
| 64 | +# True |
| 65 | +# True |
| 66 | +# True |
| 67 | +# True |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +if __name__ == '__main__': |
| 77 | + s = raw_input() |
| 78 | + |
| 79 | +print any(c.isalnum() for c in s) |
| 80 | +print any(c.isalpha() for c in s) |
| 81 | +print any(c.isdigit() for c in s) |
| 82 | +print any(c.islower() for c in s) |
| 83 | +print any(c.isupper() for c in s) |
| 84 | + |
0 commit comments