Python 2 exam

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

True/False: An exception handler is a piece of code that is written using the try/except statement.

True

True/False: Closing a file disconnects the communication between the file and the program

True

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

True

True/False: Indexing works with both strings and lists.

True

True/False: The ZeroDivisionError exception is raised when the program attempts to perform a division by zero.

True

True/False: The issubset method can be used to determine whether set1 is a subset of set2.

True

To add a single item to a set, you can use the set method _______________.

add

The _______________ method clears the contents of a dictionary

clear

What would you use if an element is to be removed from a specific index? a. del statement b. [1, 3, 5, 7, 9] c. index method d. slice method

del statement

When a program needs to save data for later use, it writes the data in a(n) _______________.

file

Assume namesList contains a list of names (as strings). Write a for-loop that walks over the list and prints out all the names.

for n in namesList: print(n)

Tuples are _______________ , which means that once a tuple is created, it cannot be changed.

immutable

The _______________ operator can be used to determine whether one string is contained in another string.

in

What method can be used to place an item in the list at a specific index? a. append b. index c. insert d. Add

insert

Which method would you use to returns all the elements in the dictionary as a list of tuples? a. list b. items c. pop d. keys

items

In a dictionary, you use a(n) _____ to locate a specific value. a. datum b. index c. item d. key

key

The built-in function _______________ returns the length of a sequence.

len()

The _______________ method returns a copy of the string with all alphabetic letters converted to lower case.

lower()

Which step creates a connection between a file and a program? a. Open the file. b. Read the file. c. Process the file. d. Close the file.

open the file

A(n) _______________ is an object that holds multiple unique items of data in an unordered manner.

set

A(n) _______________ is a span of items that are taken from a sequence.

slice

The third number in string slicing brackets or in the range() function represents the _______________ value.

step or increment

True/False: Invalid indexes do not cause slicing expressions to raise an exception.

true

True/False: The lstrip() method returns a copy of the string with all leading whitespace characters removed, but does not remove trailing whitespace characters.

true

What statement can be used to handle some of the run-time errors in a program? a. exception statement b. try statement c. try/except statement d. exception handler statement

try/except statement

What will be assigned to s_string after the execution of the following code? special = '1337 Country Ln.' s_string = special[ :4] a. '1357' b. 'Country Ln.' c. ' Country Ln.' d. Invalid code

'1357'

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

'Hello world'

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

0 through 7

What will be assigned to s_string after the execution of the following code? special = '1337 Country Ln.' s_string = special[4: ] a. '1357' b. 'Country Ln. ' c. ' Country Ln.' d. Invalid code

' Country Ln.'


Ensembles d'études connexes

Exam 1 (Exam 1&2&Final Comp+Misc)

View Set

FLUID AND ELECTROLYTE IMBALANCE EXAM 1

View Set

"The Pardoner's Prologue & Tale" from Chaucer's The Canterbury Tales

View Set

Pharm Test #1 EOC Questions + ATI Questions

View Set

Weber - ch 44-The Protestant Ethic and Spirit of Capitalism

View Set