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 Quizizz
15 questions
HCI 584 Python quiz

Quiz
•
University
8 questions
Python7

Quiz
•
Professional Development
10 questions
Array and string unit 7

Quiz
•
University
13 questions
Object oriented programming in java

Quiz
•
University
10 questions
DEBUG THE CODE

Quiz
•
University
10 questions
Q2 - Python

Quiz
•
University
15 questions
CloudBinary_Basic-Shell-scripting

Quiz
•
Professional Development
7 questions
Python Basics Day 2

Quiz
•
University
Popular Resources on Quizizz
15 questions
Character Analysis

Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing

Quiz
•
9th - 12th Grade
10 questions
American Flag

Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension

Quiz
•
5th Grade
30 questions
Linear Inequalities

Quiz
•
9th - 12th Grade
20 questions
Types of Credit

Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25

Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers

Quiz
•
6th - 8th Grade