
Python Basics: Dictionaries and Strings
Authored by Jeff Thuong
Computers
University - Professional Development
Dictionaries covered
Used 4+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How to define an empty dictionary?
my_dict = {}
my_dict = empty_dict()
my_dict = []
my_dict = ()
Answer explanation
There are two ways to define an empty dictionary:
* my_dict = {}
* my_dict = dict()
Tags
Dictionaries
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How to define a dictionary with one person (name) and its age?
ages = {"Abraham"=1000}
ages = ["Abraham": 1000]
ages = {"Abraham": 1000}
ages = ["Abraham"=1000]
Answer explanation
Curly brackets {...} for a dictionary and : to match a key to its value
Tags
Dictionaries
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How to access the value matching a key "China" in a dictionary countries?
countries{"China"}
countries["China"]
countries("China")
countries.China
Answer explanation
To access a value, we always use [...], shall it be in lists, strings (character or slice), tuples, or dictionaries
Tags
Dictionaries
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What does the following do:
my_dictionary = {"one":1, "two:2}
my_dictionary["one"] = 111
Replace the value of "one" with 111
Nothing because we already have a value "one"
Store a second value "one" with value 111
Raise an Error
Answer explanation
In a dictionary, the keys are unique, and we have a matching value for each.
Setting a new value will replace the previous one (because there is a simple way to set a value only if it does not exist).
Tags
Dictionaries
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How to check a dictionary my_dict has a certain key my_key?
my_key in my_dict
my_dict.has(my_key)
my_dict has my_key
my_dict in my_key
Answer explanation
The keyword in is used:
* To loop in "for loops"
* To check if an element is part of a list, string, or dictionary
Tags
Dictionaries
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What does the split method do (e.g. my_string.strip(...))?
Return a string with all spaces removed, even in the middle
Return a string with all spaces at the beginning and end removed
Return a list of strings (my_string being cut into slices)
Modify my_string by removing spaces and return nothing
Answer explanation
The methods on the string (like .strip() or .split(), etc.) does not change the initial string but return a modified one.
Tags
Strings
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What does the following do?
"1-2-3-4-5-6".split("-")
Return a list of numbers
[1, 2, 3, 4, 5]
Return a list of strings
["1", "2", "3", "4", "5"]
Return a string
"123456"
Raise an Error
Answer explanation
Split is cutting into a list of the strings (even if it's numbers) based on a keyword passed as argument.
Note that we can apply method directly on strings (or lists, dictionaries) without going through a variable.
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
12 questions
Python Collections Quiz
Quiz
•
Professional Development
10 questions
J277 - 2.2 - Understanding Data Types in Programming
Quiz
•
10th Grade - University
15 questions
PYTHON UNIT I MCQS
Quiz
•
University
11 questions
ChatGPT Quiz
Quiz
•
Professional Development
10 questions
Database
Quiz
•
University
10 questions
Emerging technologies
Quiz
•
6th Grade - University
10 questions
04 JavaScript Einführung
Quiz
•
Professional Development
10 questions
PreTrainingClassesObjectsMethods
Quiz
•
Professional Development
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
15 questions
Equivalent Fractions
Quiz
•
4th Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade