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.
str.isalnum()(Links to an external site.)This method checks if all the characters of a string are alphanumeric(a-z, A-Z and 0-9). >>> print 'ab123'.isalnum() True >>> print 'ab123#'.isalnum() Falsestr.isalpha()(Links to an external site.)This method checks if all the characters of a string are alphabetical(a-z and A-Z). >>> print 'abcD'.isalpha() True >>> print 'abcd1'.isalpha() Falsestr.isdigit()(Links to an external site.)This method checks if all the characters of a string are digits(0-9). >>> print '1234'.isdigit() True >>> print '123edsd'.isdigit() Falsestr.islower()(Links to an external site.)This method checks if all the characters of a string are lowercase characters(a-z). >>> print 'abcd123#'.islower() True >>> print 'Abcd123#'.islower() Falsestr.isupper()(Links to an external site.)This method checks if all the characters of a string are uppercase characters(A-Z). >>> print 'ABCD123#'.isupper() True >>> print 'Abcd123#'.isupper() False
Assignment Instructions
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here