Dictionary in Python

Beschreibung

Coding Python Quiz am Dictionary 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 fast 4 Jahre
2266
0

Zusammenfassung der Ressource

Frage 1

Frage
What is the output of the following sampleDict = dict([ ('first', 1), ('second', 2), ('third', 3) ]) print(sampleDict)
Antworten
  • [ (‘first’, 100), (‘second’, 200), (‘third’, 300) ]
  • Options: SyntaxError: invalid syntax
  • {‘first’: 1, ‘second’: 2, ‘third’: 3}

Frage 2

Frage
Select the correct ways to get the value of marks key. student = { "name": "Emma", "class": 9, "marks": 75 }
Antworten
  • m = student.get(2)
  • m = student.get(‘marks’)
  • m = student[2])
  • m = student[‘marks’])

Frage 3

Frage
Dictionary keys must be immutable
Antworten
  • True
  • False

Frage 4

Frage
Select the correct way to access the value of a history subject sampleDict = { "class":{ "student":{ "name":"Mike", "marks":{ "physics":70, "history":80 } } } }
Antworten
  • sampleDict[‘class’][‘student’][‘marks’][1]
  • sampleDict[‘class’][‘student’][‘marks’][‘history’]
  • sampleDict[‘class’][0][‘marks’][‘history’]

Frage 5

Frage
What is the output of the following code dict1 = {"key1":1, "key2":2} dict2 = {"key2":2, "key1":1} print(dict1 == dict2)
Antworten
  • True
  • False

Frage 6

Frage
What is the output of the following dictionary operation dict1 = {"name": "Mike", "salary": 8000} temp = dict1.get("age") print(temp)
Antworten
  • KeyError: ‘age’
  • None
  • { }

Frage 7

Frage
Please select all correct ways to empty the following dictionary student = { "name": "Emma", "class": 9, "marks": 75 }
Antworten
  • del student
  • del student[0:2]
  • student.clear()

Frage 8

Frage
In Python, Dictionaries are immutable
Antworten
  • True
  • False

Frage 9

Frage
Select the correct way to print Emma’s age. student = {1: {'name': 'Emma', 'age': '27', 'sex': 'Female'}, 2: {'name': 'Mike', 'age': '22', 'sex': 'Male'}}
Antworten
  • student[0][1]
  • student[1][“age”]
  • student[0][“age”]

Frage 10

Frage
What is the output of the following dictionary operation dict1 = {"name": "Mike", "salary": 8000} temp = dict1.pop("age") print(temp)
Antworten
  • KeyError: ‘age’
  • None
  • 25
  • age

Frage 11

Frage
Select all correct ways to copy a dictionary in Python
Antworten
  • dict2 = dict1.copy()
  • dict2 = dict(dict1.items())
  • dict2 = dict(dict1)
  • dict2 = dict1

Frage 12

Frage
Select the all correct way to remove the key ‘marks‘ from a dictionary student = { "name": "Emma", "class": 9, "marks": 75 }
Antworten
  • student.pop(“marks”)
  • del student[“marks”]
  • student.popitem()
  • dict1.remove(“key2”)

Frage 13

Frage
Select correct ways to create an empty dictionary
Antworten
  • sampleDict = {}
  • sampleDict = dict()
  • sampleDict = dict{}

Frage 14

Frage
Items are accessed by their position in a dictionary and All the keys in a dictionary must be of the same type.
Antworten
  • True
  • False
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