Deck 9: More About Strings

Full screen (f)
exit full mode
Question
What will be assigned to s_string after the execution of the following code? special = '1357 Country Ln.'
S_string = special[-3: ]

A) '531'
B) 'Ln.'
C) ' Ln.'
D) '7531'
Use Space or
up arrow
down arrow
to flip the card.
Question
The index - 1 identifies the last character in a string.
Question
What will be assigned to s_string after the execution of the following code? special = '1357 Country Ln.'
S_string = special[ :4]

A) '7'
B) '1357'
C) '1357 '
D) Invalid code
Question
Which of the following string methods can be used to determine if a string contains only '\n' characters?

A) ischar()
B) isalpha()
C) istab()
D) isspace()
Question
Indexing of a string starts at 1, so the index of the first character is 1, the index of the second character is 2, and so forth.
Question
Invalid indexes do not cause slicing expressions to raise an exception.
Question
In slicing, if the end index specifies a position beyond the end of the string, Python will use the length of the string instead.
Question
What will be assigned to the string variable pattern after the execution of the following code? i = 3
Pattern = 'z' * (5*i)

A) 'zzzzzzzzzzzzzzz'
B) 'zzzzz'
C) Error: '*' operator used incorrectly
D) The right side of the '*' must be an integer.
Question
What is the value of the variable string after the execution of the following code? string = 'abcd'
String.upper()

A) 'abcd'
B) 'Abcd'
C) 'ABCD'
D) Invalid code
Question
Which method would you use to determine whether a substring is the suffix of a string?

A) endswith(substring)
B) find(substring)
C) replace(string, substring)
D) startswith(substring)
Question
If the start index is _____ the end index, the slicing expression will return an empty string.

A) equal to
B) less than
C) greater than
D) not equal to
Question
What will be assigned to s_string after the execution of the following code? special = '1357 Country Ln.'
S_string = special[4: ]

A) '1357'
B) 'Country Ln.'
C) ' Country Ln.'
D) Invalid code
Question
What is the return value of the string method lstrip()?

A) The string with all whitespace removed
B) The string with all leading spaces removed
C) The string with all leading tabs removed
D) The string with all leading whitespaces removed
Question
Which list will be referenced by the variable list_strip after the execution of the following code? list_string = '03/07/2008'
List_strip = list_string.split('/')

A) ['3', '7', '2008']
B) ['03', '07', '2008']
C) ['3', '/', '7', '/', '2008']
D) ['03', '/', '07', '/', '2008']
Question
What is the first negative index in a string?

A) 0
B) -1
C) -0
D) Size of the string minus one
Question
Indexing works with both strings and lists.
Question
What will be assigned to the string variable even after the execution of the following code? special = '0123456789'
Even = special[0:10:2]

A) '13579'
B) '2468'
C) '02468'
D) Invalid code
Question
What is the value of the variable string after the execution of the following code? string = 'Hello'
String += ' world'

A) 'Hello'
B) ' world'
C) 'Hello world'
D) Invalid code
Question
Which method would you use to determine whether a substring is present in a string?

A) endswith(substring)
B) find(substring)
C) replace(string, substring)
D) startswith(substring)
Question
What are the valid indexes for the string 'New York'?

A) 0 through 7
B) 0 through 8
C) -1 through -8
D) -1 through 6
Question
The _______________ operator can be used to determine whether one string is contained in another string.
Question
The _______________ method returns a copy of the string with all alphabetic letters converted to lower case.
Question
When accessing each character in a string, such as for copying purposes, you would typically use a while loop.
Question
The _______________ method returnst if the string contains only numeric digits.
Question
A(n) _______________ is a span of characters that are taken from within a string.
Question
A(n) _______________ exception will occur if you try to use an index that is out of range for a particular string.
Question
The _______________ method returns the list of the words in the string.
Question
The strip() method returns a copy of the string with all leading whitespace characters removed, but does not remove trailing whitespace characters.
Question
An expression of the form string[i] = 'i' is a valid expression.
Question
When the operand on the left side of the * symbol is a string and the operand on the right side is an integer, it becomes the _______________ operator.
Question
The third number in string slicing brackets represents the _______________ value.
Question
Strings are _______________, which means that once a string is created, it cannot be changed.
Question
Each character in a string has a(n) _______________ which specifies its position in the string.
Question
If the + operator is used on strings, it produces a string that is the combination of the two strings used as its operands.
Question
If a whole paragraph is included in a single string, the split() method can be used to obtain a list of the sentences included in the paragraph.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/35
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 9: More About Strings
1
What will be assigned to s_string after the execution of the following code? special = '1357 Country Ln.'
S_string = special[-3: ]

A) '531'
B) 'Ln.'
C) ' Ln.'
D) '7531'
B
2
The index - 1 identifies the last character in a string.
True
3
What will be assigned to s_string after the execution of the following code? special = '1357 Country Ln.'
S_string = special[ :4]

A) '7'
B) '1357'
C) '1357 '
D) Invalid code
B
4
Which of the following string methods can be used to determine if a string contains only '\n' characters?

A) ischar()
B) isalpha()
C) istab()
D) isspace()
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
5
Indexing of a string starts at 1, so the index of the first character is 1, the index of the second character is 2, and so forth.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
6
Invalid indexes do not cause slicing expressions to raise an exception.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
7
In slicing, if the end index specifies a position beyond the end of the string, Python will use the length of the string instead.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
8
What will be assigned to the string variable pattern after the execution of the following code? i = 3
Pattern = 'z' * (5*i)

A) 'zzzzzzzzzzzzzzz'
B) 'zzzzz'
C) Error: '*' operator used incorrectly
D) The right side of the '*' must be an integer.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
9
What is the value of the variable string after the execution of the following code? string = 'abcd'
String.upper()

A) 'abcd'
B) 'Abcd'
C) 'ABCD'
D) Invalid code
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
10
Which method would you use to determine whether a substring is the suffix of a string?

A) endswith(substring)
B) find(substring)
C) replace(string, substring)
D) startswith(substring)
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
11
If the start index is _____ the end index, the slicing expression will return an empty string.

A) equal to
B) less than
C) greater than
D) not equal to
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
12
What will be assigned to s_string after the execution of the following code? special = '1357 Country Ln.'
S_string = special[4: ]

A) '1357'
B) 'Country Ln.'
C) ' Country Ln.'
D) Invalid code
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
13
What is the return value of the string method lstrip()?

A) The string with all whitespace removed
B) The string with all leading spaces removed
C) The string with all leading tabs removed
D) The string with all leading whitespaces removed
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
14
Which list will be referenced by the variable list_strip after the execution of the following code? list_string = '03/07/2008'
List_strip = list_string.split('/')

A) ['3', '7', '2008']
B) ['03', '07', '2008']
C) ['3', '/', '7', '/', '2008']
D) ['03', '/', '07', '/', '2008']
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
15
What is the first negative index in a string?

A) 0
B) -1
C) -0
D) Size of the string minus one
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
16
Indexing works with both strings and lists.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
17
What will be assigned to the string variable even after the execution of the following code? special = '0123456789'
Even = special[0:10:2]

A) '13579'
B) '2468'
C) '02468'
D) Invalid code
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
18
What is the value of the variable string after the execution of the following code? string = 'Hello'
String += ' world'

A) 'Hello'
B) ' world'
C) 'Hello world'
D) Invalid code
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
19
Which method would you use to determine whether a substring is present in a string?

A) endswith(substring)
B) find(substring)
C) replace(string, substring)
D) startswith(substring)
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
20
What are the valid indexes for the string 'New York'?

A) 0 through 7
B) 0 through 8
C) -1 through -8
D) -1 through 6
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
21
The _______________ operator can be used to determine whether one string is contained in another string.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
22
The _______________ method returns a copy of the string with all alphabetic letters converted to lower case.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
23
When accessing each character in a string, such as for copying purposes, you would typically use a while loop.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
24
The _______________ method returnst if the string contains only numeric digits.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
25
A(n) _______________ is a span of characters that are taken from within a string.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
26
A(n) _______________ exception will occur if you try to use an index that is out of range for a particular string.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
27
The _______________ method returns the list of the words in the string.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
28
The strip() method returns a copy of the string with all leading whitespace characters removed, but does not remove trailing whitespace characters.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
29
An expression of the form string[i] = 'i' is a valid expression.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
30
When the operand on the left side of the * symbol is a string and the operand on the right side is an integer, it becomes the _______________ operator.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
31
The third number in string slicing brackets represents the _______________ value.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
32
Strings are _______________, which means that once a string is created, it cannot be changed.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
33
Each character in a string has a(n) _______________ which specifies its position in the string.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
34
If the + operator is used on strings, it produces a string that is the combination of the two strings used as its operands.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
35
If a whole paragraph is included in a single string, the split() method can be used to obtain a list of the sentences included in the paragraph.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 35 flashcards in this deck.