Sets in Python

Beschreibung

Coding Python Quiz am Sets in Python, erstellt von PathaPadha Support am 27/10/2020.
PathaPadha Support
Quiz von PathaPadha Support, aktualisiert more than 1 year ago
PathaPadha Support
Erstellt von PathaPadha Support vor etwa 4 Jahre
638
0

Zusammenfassung der Ressource

Frage 1

Frage
What is the output of the following ? sampleSet = {"Yellow", "Orange", "Black"} sampleSet.add("Blue") sampleSet.add("Orange") print(sampleSet)
Antworten
  • {‘Blue’, ‘Orange’, ‘Yellow’, ‘Orange’, ‘Black’}
  • {‘Blue’, ‘Orange’, ‘Yellow’, ‘Black’}

Frage 2

Frage
The union() method returns a new set with all items from both sets by removing duplicates
Antworten
  • True
  • False

Frage 3

Frage
Select all the correct ways to copy two sets
Antworten
  • set2 = set1.copy()
  • set2 = set1
  • set2 = set(set1)
  • set2.update(set1)

Frage 4

Frage
What is the output of the following sampleSet = {"Yellow", "Orange", "Black"} sampleSet.discard("Blue") print(sampleSet)
Antworten
  • {‘Yellow’, ‘Orange’, ‘Black’}
  • KeyError: ‘Blue’

Frage 5

Frage
The symmetric_difference() method returns a set that contains all items from both sets, but not the items that are present in both sets.
Antworten
  • True
  • False

Frage 6

Frage
What is the output of the following code aSet = {1, 'PYnative', ['abc', 'xyz'], True} print(aSet)
Antworten
  • {1, ‘PYnative’, [‘abc’, ‘xyz’]}
  • {1, ‘PYnative’, [‘abc’, ‘xyz’], True}
  • TypeError

Frage 7

Frage
Select which is true for Python set
Antworten
  • Sets are unordered.
  • Set doesn’t allow duplicate
  • sets are written with curly brackets {}
  • set Allows duplicate
  • set is immutable
  • a set object does support indexing

Frage 8

Frage
What is the output of the following set operation. set1 = {"Yellow", "Orange", "Black"} set2 = {"Orange", "Blue", "Pink"} set1.difference_update(set2) print(set1)
Antworten
  • {‘Black’, ‘Yellow’}
  • {‘Yellow’, ‘Orange’, ‘Black’, ‘Blue’, ‘Pink’}

Frage 9

Frage
What is the output of the following code sampleSet = {"Yellow", "Orange", "Black"} print(sampleSet[1])
Antworten
  • Yellow
  • Syntax Error
  • Orange

Frage 10

Frage
What is the output of the following union operation set1 = {10, 20, 30, 40} set2 = {50, 20, "10", 60} set3 = set1.union(set2) print(set3)
Antworten
  • {40, 10, 50, 20, 60, 30}
  • {40, ’10’, 50, 20, 60, 30}
  • {40, 10, ’10’, 50, 20, 60, 30}
  • SynatxError: Different types cannot be used with sets

Frage 11

Frage
What is the output of the following set operation set1 = {"Yellow", "Orange", "Black"} set2 = {"Orange", "Blue", "Pink"} set3 = set2.difference(set1) print(set3)
Antworten
  • {‘Yellow’, ”Black’, ‘Pink’, ‘Blue’}
  • {‘Pink’, ‘Blue’}
  • {‘Yellow’, ”Black’}

Frage 12

Frage
Select all the correct options to remove “Orange” from the set. sampleSet = {"Yellow", "Orange", "Black"}
Antworten
  • sampleSet.pop(“Orange”)
  • sampleSet.discard(“Orange”)
  • sampleSet.discard('Orange')
  • del sampleSet [“Orange”]

Frage 13

Frage
What is the output of the following set1 = {10, 20, 30, 40, 50} set2 = {60, 70, 10, 30, 40, 80, 20, 50} print(set1.issubset(set2)) print(set2.issuperset(set1))
Antworten
  • False False
  • True True
  • False True
  • True False

Frage 14

Frage
What is the output of the following set operation sampleSet = {"Yellow", "Orange", "Black"} sampleSet.update(["Blue", "Green", "Red"]) print(sampleSet)
Antworten
  • {‘Yellow’, ‘Orange’, ‘Red’, ‘Black’, ‘Green’, ‘Blue’}
  • {‘Yellow’, ‘Orange’, ‘Black’, [“Blue”, “Green”, “Red”]}
  • TypeError: update() doesn’t allow list as a argument.

Frage 15

Frage
What is the output of the following code aSet = {1, 'PYnative', ('abc', 'xyz'), True} print(aSet)
Antworten
  • TypeError
  • {‘PYnative’, 1, (‘abc’, ‘xyz’), True}
  • {‘PYnative’, 1, (‘abc’, ‘xyz’)}
Zusammenfassung anzeigen Zusammenfassung ausblenden

ähnlicher Inhalt

Python Quiz
karljmurphy
Think Python
tsilvo2001
Basic Python - Print Formatting
Rebecca Noel
What is Python?
Daniel Ingram
Python
54671
Know your Python!
educ8ict
Basic Python - Strings
Rebecca Noel
Study on IoT systems design
Tomasz Cieplak
Python
Kirstie Wu
OpenSource Programming
Faheem Ahmed
Basic Python - Lists
Rebecca Noel