strings Flashcards
check each word from capital
‘The Hilton’.istitle()
check string contains another string
‘plane’ in ‘The worlds fastest plane’
find index of substing or -1
‘The worlds fastest plane’.find(‘plane’)
find index or ValueError
‘The worlds fastest plane’.index(‘car’)
‘the happiest person in the whole wide world.’.index(‘the’,10,44)
how many substings
‘The first president of the organization..’.count(‘o’)
make first symbol capital
‘florida dolphins’.capitalize()
f-sting exaple
f’Hello. My name is {name} and I like {food}.’
if string contains only numbers
‘80000’.isnumeric()
if only lowercase
‘all lower case’.islower()
all symbols is ascii
‘A’.isascii()
change register
sentence. upper() #=> ‘THE CAT IN THE HAT’
sentence. lower() #=> ‘the cat in the hat’
if only uppercase
‘Toronto’.isupper() #=> False
‘TORONTO’.isupper() #= True
if only alphabet characters
‘One1’.isalpha() #=> False
‘One’.isalpha() #=> True
if number and alphabet characters
‘Ten10’.isalnum() #=> True
‘Ten10.’.isalnum() #=> False
remove spaces
string = ‘ string of whitespace ‘
string. lstrip() #=> ‘string of whitespace ‘
string. rstrip() #=> ‘ string of whitespace’
string. strip() #=> ‘string of whitespace’