- Home
- Course Detail
regularpython@gmail.com
You are now watching:
Python Strings / of Is Functions in String
#isalnum():Checks Alphanumeric Character #without any special characters # 0-9a-zA-Z name = "tutorials tution com is a website com" name ="tutorials9090" Result = name.isalnum() print(Result) name = "tutorialstution.com" Result = name.isalnum() print(Result) #========================================================================== #isalpha():Checks if All Characters are Alphabets #only a-z name = "tutorials tution.com is a website .com" name ="tutorials0" Result = name.isalpha() print(Result) name = "tutorialstution.com" Result = name.isalpha() print(Result) #========================================================================== #isdecimal():Checks Decimal Characters #only 0-9 but in string format name = "tutorials tution.com is a website .com" name = "67676" Result = name.isdecimal() print(Result) name = "tutorialstution.com" Result = name.isdecimal() print(Result)
#========================================================================== #isdigit():Checks Digit Characters #only 0-9 name = "tutorials tution.com is a website .com" name="565656kk" Result = name.isdigit() print(Result) name = "tutorialstution.com" Result = name.isdigit() print(Result) #There are differences, but they're somewhat rare*. It mainly crops up with various unicode characters, c = '\u00B2' print(c.isdecimal()) print(c.isdigit()) #========================================================================== #isidentifier():Checks for Valid Identifier #checks string is valid identifier or not name = "tutorials tution.com is a website .com" Result = name.isidentifier() print(Result) name = "tutorialstution.com" Result = name.isidentifier() print(Result)
#========================================================================== #islower():Checks if all Alphabets in a String are Lowercase #checks string is lower or not name = "tutorials tution.com is a website .com" Result = name.islower() print(Result) #========================================================================== #isnumeric():Checks Numeric Characters #if all characters in a string are numeric characters. If not, it returns False. #numeric characters = fraction, roman numerals, currency numerators s = '\u00B23455' if s.isnumeric() == True: print('All characters are numeric.') else: print('All characters are not numeric.')
#========================================================================== #isprintable():Checks Printable Character #True if all characters in the string are printable or the string is empty. If not, it returns False. #Characters that occupies printing space on the screen are known as printable characters #Printable Character= letters and symbols,digits,punctuation,whitespace s = 'Space is a printable' print(s) print(s.isprintable()) s = '\nNew Line is printable' print(s) print(s.isprintable()) s = '' print('\nEmpty string printable?', s.isprintable()) #========================================================================== #isspace():Checks Whitespace Characters #True if there are only whitespace characters in the string. If not, it return False. #Whitespace characters = space, tab s = '\t \n' if s.isspace() == True: print('All whitespace characters') else: print('Contains non-whitespace characters') s = '2+2 = 4' if s.isspace() == True: print('All whitespace characters') else: print('Contains non-whitespace characters.') #========================================================================== #istitle():Checks for Titlecased String #True if the string is a titlecased string. If not, it returns False #First letter must and should uppercase s = 'I Love Python.' if s.istitle() == True: print('Titlecased String') else: print('Not a Titlecased String') s = 'PYthon' if s.istitle() == True: print('Titlecased String') else: print('Not a Titlecased String') #========================================================================== #isupper():returns if all characters are uppercase characters #True if all characters of a string uppercase else returns false #Ex:TUTORIALSTUTION string = 'THIS IS GOOD' if string.isupper() == True: print('Does not contain lowercase letter.') else: print('Contains lowercase letter.') string = 'THIS IS gOOD' if string.isupper() == True: print('Does not contain lowercase letter.') else: print('Contains lowercase letter.')