### Some string function examples #### Booleans '555'.isalnum() 'five five five'.isalnum() '1fiftyfive'.isalnum() '555'.isdigit() '555'.isnumeric() '\u2155'.isnumeric() '\u2155'.isdigit() ## this character does not print to my screen, but ##################### apparently is 1/5 'bug'.isidentifier() '545'.isidentifier() 'abc'.islower() 'abc'.isupper() 'ABC'.islower() 'ABC'.isupper() 'Gone With The Wind'.istitle() ' '.isprintable() emu = 'abc'+chr(127) emu.isprintable() ' '.isspace() 'Books'.endswith('es') 'Books'.endswith('s') 'Preschool'.startswith('Story Time') 'Preschool'.startswith('Pre') ##### Case Changing Functions 'hello world'.capitalize() 'hello world'.title() 'hello world'.upper() 'HELLO WORLD'.lower() 'HELLO WORLD'.title() 'Hello World'.swapcase() #### Formatting Functions 'Hello World'.center(20,'*') 'Hello World'.ljust(20,'*') 'Hello World'.rjust(20,'*') '{whose} {thing} is nice'.format(whose = 'John\'s', thing = 'code') ### Search Functions 'The big bad bug bled bad blood'.find('bad') 'The big bad bug bled bad blood'.rfind('bad') 'The big bad bug bled bad blood'.index('bad') 'The big bad bug bled bad blood'.rindex('bad') ## difference between find/rfind and index/rindex ## when search fails: find/rfind return -1 ## index/rindex cause an error to occur ### Stripping off characters (e.g., spaces) ' Hello World '.strip(' ') ' Hello World '.lstrip(' ') ' Hello World '.rstrip(' ') ### String splitting 'Five Hundred Fifty Five'.split(' ') ### rsplit searches form right (subtle difference) '''Five hundred fifty five Three hundred one Seventy three'''.splitlines() 'Five Hundred Fifty Five'.partition(' ') 'Five Hundred Fifty Five'.rpartition(' ')