Ch 8

¡Supera tus tareas y exámenes ahora con Quizwiz!

When accessing each character in a string, such as for copying purposes, you would typically use a while loop.

False

You cannot use a for loop to iterate over the characters in a string.

False

If a whole paragraph is included in a single string, the split() method can be used to obtain a list of the sentences in the paragraph.

True

If the + operator is used on strings, it produces a string that is a combination of the two strings used as its operands.

True

Indexing works with both strings and lists.

True

The index -1 identifies the last character of a string.

True

Which method would you use to determine whether a certain substring is present in a string?

find(substring)

If the start index is ________ the end index, the slicing expression will return an empty string.

greater than

What will be displayed after the following code executes? mystr = 'yes' yourstr = 'no' mystr += yourstr * 2 print(mystr)

yesnono

What is the first negative index in a string?

-1

What are the valid indexes for the string 'New York'?

0 through 7

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.

False

The following code will display 'yes + no': mystr = 'yes' yourstr = 'no' mystr += yourstr print(mystr)

False

The following expression is valid: string[i] = 'i'

False

The strip() method returns a copy of the string with all the leading whitespace characters removed but does not remove trailing whitespace characters.

False

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[4:]

' Country Ln.'

What will be assigned to the variable some_nums after the following code executes? special = '0123456789' some_nums = special[0:10:2]

'02468'

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[ :4]

'1357'

What will be the value of the variable string after the following code executes? string = 'abcd' string.upper()

'ABCD'

What will be the value of the variable string after the following code executes? string = 'abcd' string.upper()

'ABCD'

What will be the value of the variable string after the following code executes? string = 'Hello' string += ' world!'

'Hello world!'

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[-3:]

'Ln.'

What will display after the following code executes? password = 'ILOVEPYTHON' if password.isalpha(): print('Invalid, must contain one number.') elif password.isdigit(): print('Invalid, must have one non-numeric character.') elif password.isupper(): print('Invalid, cannot be all uppercase characters.') else: print('Your password is secure!')

Invalid, must contain one number.

What list will be referenced by the variable list_strip after the following code executes? my_string = '03/07/2018' list_strip = my_string.split('/')

['03', '07', '2018']

Which method would you use to determine whether a certain substring is the suffix of a string?

endswith(substring)

What is the return value of the string method lstrip()?

the string with all leading white spaces removed


Conjuntos de estudio relacionados

Managerial Accounting Chapter 14

View Set

Vertebrate Zoology Midterm- Malone University

View Set

NU230 Therapeutics - Chapter 11 health, wellness, and integrative healthcare

View Set

vocab quiz for crutcher on 2-27-19

View Set