strings Flashcards

1
Q

check each word from capital

A

‘The Hilton’.istitle()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

check string contains another string

A

‘plane’ in ‘The worlds fastest plane’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

find index of substing or -1

A

‘The worlds fastest plane’.find(‘plane’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

find index or ValueError

A

‘The worlds fastest plane’.index(‘car’)

‘the happiest person in the whole wide world.’.index(‘the’,10,44)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

how many substings

A

‘The first president of the organization..’.count(‘o’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

make first symbol capital

A

‘florida dolphins’.capitalize()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

f-sting exaple

A

f’Hello. My name is {name} and I like {food}.’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

if string contains only numbers

A

‘80000’.isnumeric()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

if only lowercase

A

‘all lower case’.islower()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

all symbols is ascii

A

‘A’.isascii()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

change register

A

sentence. upper() #=> ‘THE CAT IN THE HAT’

sentence. lower() #=> ‘the cat in the hat’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

if only uppercase

A

‘Toronto’.isupper() #=> False

‘TORONTO’.isupper() #= True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

if only alphabet characters

A

‘One1’.isalpha() #=> False

‘One’.isalpha() #=> True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

if number and alphabet characters

A

‘Ten10’.isalnum() #=> True

‘Ten10.’.isalnum() #=> False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

remove spaces

A

string = ‘ string of whitespace ‘

string. lstrip() #=> ‘string of whitespace ‘
string. rstrip() #=> ‘ string of whitespace’
string. strip() #=> ‘string of whitespace’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

check if the string starts or ends with substring

A

city = ‘New York’

city. startswith(‘New’) #=> True
city. endswith(‘N’) #=> False

17
Q

if only spaces

A

’‘.isspace() #=> False
‘ ‘.isspace() #=> True
‘ ‘.isspace() #=> True
‘ the ‘.isspace() #=> False

18
Q

fist character to uppercase

A

‘once upon a time’.title() #=> ‘Once Upon A Time’

19
Q

translate example

A
mapping = str.maketrans("abcs", "123S")
"abc are the first three letters".translate(mapping)
#=> '123 1re the firSt three letterS'
20
Q

find from right

A

story = ‘The price is right said Bob. The price is right.’

story.rfind(‘is’)