Python From Beginner to Advanced

0% completed

Previous
Next
Quiz
What is the primary characteristic of a set in Python?
A
Sets are ordered collections.
B
Sets can contain duplicate elements.
C
Sets ensure elements are unique and unordered.
D
Sets allow mutable elements.
What will be the output of the following code?
set1 = {1, 2, 3, 4}
set2 = {3, 4, 5, 6}
difference = set1.difference(set2)
print(difference)
A
{1, 2}
B
{3, 4}
C
{5, 6}
D
{1, 2, 3, 4}
What does the following set method do?
fruits = {'apple', 'banana', 'cherry'}
fruits.clear()
print(fruits)
A
{'apple', 'banana', 'cherry'}
B
{}
C
{'cherry'}
D
Error
What is the result of the following set operation?
set1 = {1, 2, 3}
set2 = {3, 4, 5}
result = set1.union(set2)
print(result)
A
{3}
B
{1, 2, 4, 5}
C
Error
D
{1, 2, 3, 4, 5}
How does a set differ from a list in terms of storage and performance?
A
Sets store elements more compactly and provide faster access.
B
Lists store elements more efficiently and allow quicker modifications.
C
Sets provide faster lookups compared to lists, especially for large data sets.
D
Lists are always faster for accessing elements by index.

.....

.....

.....

Like the course? Get enrolled and start learning!
Previous
Next