Starting out with Python Chapter 9

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

You can use the ___ operator to find the intersection of two sets.

&

After the following statement executes, what elements will be store in the myset set? myset = set('Jupiter')

'J', 'u', 'p', 'i', 't', 'e', 'r'

You can use the ___ operator to find the difference of two sets.

-

What will the following code display? stuff = {1 : 'aaa', 2 : 'bbb', 3 : 'ccc'} for k in stuff: print(k)

1 2 3

What will the following code display? stuff = {1 : 'aaa', 2 : 'bbb', 3 : 'ccc'} print(len(stuff))

3

You can use the ___ operator to determine if one set is a subset of another.

<=

You can use the ___ operator to determine if one set is a superset of another.

>=

What does the item method return?

All key-value pairs in a dictionary as a sequence of tuples.

What does the keys method return?

All keys in a dictionary as a sequence of tuples.

What does the values method return?

All values in a dictionary as a sequence of tuples.

Suppose a dictionary names employee has been created. What does the following statement do? employee['id'] = 54321

Creates a key named id with 54321 as an associated value.

Suppose a dictionary named inventory exists. What does the following statement do? del inventory[654]

Deletes the key and value associated with 654.

Dictionaries are unordered. (True or False)

False

Sets are immutable objects. (True or False)

False

You can have duplicate keys in a dictionary. (True or False)

False

If they key does not exist in a dictionary what type of exception is raised?

KeyError

Does a set allow you to store duplicate elements?

No

What is the difference between the dictionary methods pop and popitem?

Pop takes a specific key, returns it, then removes that key-value pair from the dictionary. Popitem takes a random key, returns it as a tuple, then removes that key-value pair from the dictionary.

What is the difference between the remove method and discard method in sets?

The remove method will raise a KeyError exception if an invalid key is used, the discard method does not.

All elements in a set must be unique. No two elements can have the same value. (True or False)

True

Sets are unordered. (True or False)

True

The elements that are stored in a data set can be of different data types. (True or False)

True

The values in a dictionary can be objects of any type, but keys must be immutable objects. (True or False)

True

You can delete elements in a dictionary using a del method? (True or False)

True

How can you determine whether a key-value pair exists in a dictionary?

Use the in operator.

How do you create an empty set?

You call the built-in set function.

You can use the ___ operator to find the symmetric difference of sets.

^

You can use the ___ method to add an element to a set.

add

What will the following code display? stuff = {1 : 'aaa', 2 : 'bbb', 3 : 'ccc'} print(stuff[3])

ccc

You can clear all of the elements in a set by using the ________ method.

clear

What method would you use to clear the contents of a dictionary?

clear()

A __________ is an object that stores a collection of data.

dictionary

What is the format used to retrieve a value from a dictionary?

dictionary_name[key]

What format would you use to add new key-value pairs to a dictionary with an assignment statement?

dictionary_name[key] = value

The ________ of two sets is the elements that appear in set1 but not in set2.

difference

The ______ method gets a value associated with a specific key. If the key is not found, the method does not return an exception, but returns a default value.

get()

What operator would you use to prevent a KeyError from being raised if you attempt to call a key that does not exist?

in

How can you determine whether a specific element exists in a set?

in operator

The ____________ of two sets is a set that contains only the elements that are found in both sets.

intersection

What method would you call to determine if one set is a subset of another?

issubset()

What method would you call to determine if one set is a superset of another?

issuperset()

The ___ method returns all the keys in a dictionary and their associated values as a sequence of tuples.

items

Which part of a dictionary element must be immutable?

key

You use a _______ to locate a specific value in a dictionary.

key

What are the two parts of each element in a dictionary?

key and value

Dictionary elements are commonly referred to as _____________________.

key-value pairs

The ____ method returns all the keys in a dictionary as a sequence of tuples.

keys()

How do you determine the number of elements in a set?

len

You can use the ___ function to get the number of elements in a dictionary.

len

What function would you use to get the number of elements in a set?

len()

Key-value pairs are often referred to as _____________.

mappings

The type of assignment in which multiple variables are assigned is called ______.

multiple assignment

Write a statement that would clear the contents of a dictionary named phonebook.

phonebook.clear()

Write an items statement for a dictionary named phonebook.

phonebook.items()

Write a keys statement for a dictionary named phonebook.

phonebook.keys()

The ___ method returns the value associated with a specific key and removes that key-value pair from the dictionary. If the key is not found, the method returns a default value.

pop

The ____ method returns a randomly selected key-value pair as a tuple from the dictionary and removes that key-value pair from the dictionary.

popitem

A ___ is a unique object that stores a collection of data in the same way as mathematical sets.

set

Suppose 'start' : 1472 is an element in a dictionary. What is the key?

start

The _________________ of sets is a set that contains elements that are not shared by the sets.

symmetric difference

The ______ of two sets is a set that contains all the elements in both sets.

union

Are the elements of a set ordered or unordered?

unordered

What method would you use to add a group of elements to a set all at one time?

update

The _____ method returns all the values in the dictionary as a sequence of tuples.

values

Fill in the blank to create an empty dictionary: phonebook = _____

{}

What would you use to create a dictionary?

{}

You can use the ____ operator to find the union of two sets.

|


Kaugnay na mga set ng pag-aaral

NURS 270 EXAM 3 Module 5 & 6 PrepU

View Set

CompTIA A+ Core 2 Objective 3 -- 1102 Objective 3

View Set

Photography Final Exam - Photographs

View Set

Statistics & Research Methods Exam One

View Set

Prepu: Chapter 15: Nursing Care of the Child with an Infection

View Set