Search Header Logo

Sets, Tuples, Dictionary

Authored by Chong May

Computers

University

Used 1+ times

Sets, Tuples, Dictionary
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

12 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

Which statement correctly describes a Python set?

Elements within a set must be mutable types.

Sets are mutable, allowing additions and removals of elements.

A set is an ordered collection of unique items

Sets allow duplicate elements.

Answer explanation

A set is an unordered collection of unique items.

Elements within a set must be immutable types.

Sets does not allow duplicate elements.

2.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

How do you add a single element to a Python set named `my_set`?

Using `my_set[index] = element`

Using `my_set.insert(element)`

Using `my_set.append(element)`

Using `my_set.add(element)`

3.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

Which set operation in Python returns a new set containing all unique elements from both sets?

set1.union(set2)

set1.difference(set2)

set1.symmetric_difference(set2)

set1.intersection(set2)

4.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

When would you typically use a Python set instead of a list?

To maintain the order of elements for fast retrieval.

To maintain the order of elements for fast retrieval.

To store a collection of unique items where order does not matter.

To store key-value pairs.

Answer explanation

Sets are ideal for membership testing and eliminating duplicates because they only store unique, unordered elements.

5.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

How do you add a new key-value pair to a Python dictionary named `my_dict`?

my_dict.add(key, value)

my_dict.append(key, value)

my_dict.insert(key, value)

my_dict[key] = value

6.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

In what scenario would you prefer using a tuple over a list in Python?

When you need to map keys to values.

When you need an ordered collection of items that should not change.

When you need a collection where elements can be modified frequently.

When you need to store unique items and perform set operations.

7.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

Which characteristic is true about Python dictionaries?

Values must be unique.

Keys can be any mutable type.

They are accessed by index.

They are ordered collections of key-value pairs.

Answer explanation

Dictionaries are accessed by their keys, not by numerical indices.

Keys can be only immutable type.

Values may not be unique within a dictionary, but keys are.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?

Discover more resources for Computers