Exam 3

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

You can add a group of elements to a set with this method. append add update merge

update

Which of the following statements creates a tuple? values = [1, 2, 3, 4] values = {1, 2, 3, 4} values = (1) values = (1, )

values = (1, )

You can use ______ to create an empty dictionary. {} () [] empty()

{}

This built-in function returns the highest value in a list. highest max greatest best_of

max

A(n) ______________ method stores a value in a data attribute or changes its value in some other way. modifier constructor mutator accessor

mutator

Assume the following statement appears in a program. mylist = [] Which of the following statements would you use to add the string 'Labrador' to the list at index 0? mylist[0] = 'Labrador' mylist.insert(0, 'Labrador') mylist.append('Labrador') mylist.insert('Labrador', 0)

mylist.insert(0, 'Labrador')

The _____________ programming practice is centered on creating objects. object-centric objective procedural object-oriented

object-oriented

The _______ dictionary method returns the value associated with a specified key and removes that key-value pair from the dictionary. pop() random() popitem() rand_pop()

pop()

The _____ method returns and removes a randomly selected key-value pair from a dictionary. pop() random() popitem() rand_pop()

popitem()

The ____________ programming practice is centered on creating functions that are separate from the data that they work on. modular procedural functional object-oriented

procedural

This file object method returns a list containing the file's contents. to_list getlist readline readlines

readlines

This set method removes an element and raises an exception if the element is not found. remove discard delete erase

remove

When the * operator's left operand is a list and its right operand is an integer, the operator becomes this. multiplication operator repetition operator initialization operator Nothing -- the operator does not support those types of operands

repetition operator

Which of the following is a method called set_skies that has one parameter, a String. A. def set_skies(self, skies): self.skies B. skies = 0; def set_skies(self, skies): self.skies = skies C. skies = ""; def set_skies(self, skies): self.skies = skies D. skies = 0.0; def set_skies(self, skies): self.skies = skies

skies = ""; def set_skies(self, skies): self.skies = skies

This string method returns a copy of the string with all leading and trailing whitespace characters removed. clean strip remove_whitespace rstrip

strip

A set of standard diagrams for graphically depicting object-oriented systems is provided by __________ . the Unified Modeling Language flowcharts pseudocode the Object Hierarchy System

the Unified Modeling Language

You use _________ to delete an element from a dictionary. the remove method the erase method the delete method the del statement

the del statement

This string method returns a copy of the string with all leading whitespace characters removed. lstrip rstrip remove strip_leading

lstrip

The __________ method is automatically called when an object is created. _ _ init _ _ init _ _ str _ _ _ _ object _ _

_ _ init _ _

A(n) ___________ method gets the value of a data attribute but does not change it. retriever constructor mutator accessor

accessor

You can add one element to a set with this method. append add update merge

add

This list method adds an item to the end of an existing list. add add_to increase append

append

By doing this, you can hide a class's attribute from code outside the class. Avoid using the self parameter to create the attribute Begin the name of the attribute with two underscores Begin the name of the attribute with private_ _ Begin the name of the attribute with the @ symbol

begin the name of the attribute with two underscores

If a class has a method named _ _ str _ _, which of these is a way to call the method? You call it like any other method: object _ _ str _ _ () By passing an instance of the class to the built in str function The method is automatically called when the object is created By passing an instance of the class to the built-in state function

by passing an instance of the class to the built in str function

A(n) ___________ is a component of a class that references data. method instance data attribute module

data attribute

Select the answer that demonstrates a method called get_value that doesn't accept any parameters. It returns the value of the instance variable counter. A. def __init__(self): self.counter = 0 B. def get_value(): C. def get_value(): return result D. def get_value(self): return self.counter

def get_value(self): return self.counter

The _________ function returns the number of elements in a dictionary. size() len() elements() count()

len()

The following function returns the number of elements in a set. size() len() elements(0 count()

len()

Which of the following is a method called increment that adds one to the instance variable counter. It does not accept parameters or return a value. A. def increment(self): self.counter += 1 B. def increment(): counter += 1 C. def increment(): self.counter == 1 D. def increment(self): self.counter *= 1

A. def increment(self): self.counter += 1

This will happen if you try to use an index that is out of range for a list. A ValueError exception will occur. An IndexError exception will occur. The ist will be erased and the program will continue to run. Nothing -- the invalid index will be ignored.

An IndexError exception will occur.

This string method returns true if a string contains only numeric digits and is at least one character in length. The digit method. The isdigit method The numeric method The isnumber method

The isdigit method

This operator can be used to find the intersection of two sets. | & -- ^

&

This is the first index in a list. -1 0 1 the size of the list minus one

0

This is the first index in a string. -1 1 0 The size of the string minus one.

0

In the list below, what is the index of the value 30? numbers = [10, 20, 30, 40, 50] -2 3 2 -1

2

This will happen if you try to use an index that is out of range for a string. A ValueError exception will occur. A IndexError exception will occur. The string will be erased and the program will continue to run. Nothing -- the invalid index will be ignored.

A IndexError exception will occur.

If you call the index method to locate an item in a list and the item is not found, this happens. A ValueError exception is raised. An InvalidIndex exception is raised. The method returns -1 Nothing happes. the program continues running at the next statement.

A ValueError exception is raised.

This is the last index in a list. 1 99 0 The size of the list minus one

The size of the list minus one

This is the last index in a string. 1 99 0 The size of the string minus one.

The size of the string minus one.

This set method removes an element, but does not raise an exception if the element is not found. remove discard delete erase

discard

This term refers to an individual item in a list. element bin cubbyhole slot

element

This string method returns the lowest index in the string where a specified substring is found. first_index_of locate find index_of

find

The __________ dictionary method returns the value associated with a specified key. If the key is not found, it returns a default value. pop() key() value() get()

get()

Which answer defines a method called set_high that has one parameter, an int. A. def set_high(self, high): self.high high = 0.0; B. def set_high(self, high): self.high = high C. high = 0; def set_high(self, high): self.high = high D. high = ""; def set_high(self, high): self.high = high

high = 0; def set_high(self, high): self.high = high

This operator determines whether one string is contained inside another string. contains is_in == in

in

You can use the ______________ operator to determine whether a key exists in a dictionary. & in ^ ?

in

This is a number that identifies an item in a list. element index bookmark identifier

index

An object is a(n) __________. blueprint cookie cutter variable instance

instance

The ______ method returns all of a dictionary's keys and their associated values as a sequence of tuples. keys_values() values() items() get()

items()

This function returns the enth of a list. length size len lengthof

len

This function returns the length of a string. length size len lengthof

len

Select an answer displaying a constructor that takes one int argument and assigns its value to counter. A. def __init__(self): self.counter = 0 B. def init (self): self.result = 1 C. def __init__(self): self.result = 1 D. counter += 1

A. def __init__(self): self.counter = 0

This string method returns true if a string contains only alphabetic characters and is at least one character in length. The isalpha method The alpha method The alphabetic method The isletters method

The isalpha method

This removes an item at a specific index in a list. the remove method the delete method the del statement the kill method

the del statement

This operator can be used to find the union of two sets. | & -- ^

|


Kaugnay na mga set ng pag-aaral

Salesforce Certified Marketing Associate

View Set

Types of fires and extinguishers

View Set

World Science Fiction Terminology

View Set

International Marketing Chapter 8

View Set

Chapter 28: Disorders of Cardiac Conduction and Rhythm Patho Prep U

View Set

Chapter 3: Transfer of Real Property

View Set

Introduction to Probability Unit Test Review and Test 100%

View Set