Python Basics: Dictionaries and Strings

Quiz
•
Computers
•
University - Professional Development
•
Medium
Standards-aligned
Jeff Thuong
Used 4+ times
FREE Resource
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.
Create a free account and access millions of resources
Similar Resources on Wayground
10 questions
Q2 - Python

Quiz
•
University
10 questions
C Program Array and strings

Quiz
•
University
10 questions
Java Strings

Quiz
•
1st Grade - Professio...
10 questions
PYTHON_CHAPTER 7

Quiz
•
University
15 questions
Python6

Quiz
•
Professional Development
10 questions
CSE 6R Midterm Review

Quiz
•
University
10 questions
PYTHON_CHAPTER 6

Quiz
•
University
15 questions
Py-Hackathon - Week 2 - Day 2

Quiz
•
University
Popular Resources on Wayground
50 questions
Trivia 7/25

Quiz
•
12th Grade
11 questions
Standard Response Protocol

Quiz
•
6th - 8th Grade
11 questions
Negative Exponents

Quiz
•
7th - 8th Grade
12 questions
Exponent Expressions

Quiz
•
6th Grade
4 questions
Exit Ticket 7/29

Quiz
•
8th Grade
20 questions
Subject-Verb Agreement

Quiz
•
9th Grade
20 questions
One Step Equations All Operations

Quiz
•
6th - 7th Grade
18 questions
"A Quilt of a Country"

Quiz
•
9th Grade