Python Basics: Dictionaries and Strings

Python Basics: Dictionaries and Strings

University - Professional Development

10 Qs

quiz-placeholder

Similar activities

Cybernaut Analysis

Cybernaut Analysis

University

15 Qs

Python Quiz 2.0

Python Quiz 2.0

University

14 Qs

QUIZ-5: MYSQL & File Handling

QUIZ-5: MYSQL & File Handling

University

15 Qs

PYTHON INTRODUCTION

PYTHON INTRODUCTION

Professional Development

15 Qs

Python revision

Python revision

10th Grade - University

15 Qs

Day 2

Day 2

Professional Development

10 Qs

Python Dictionaries

Python Dictionaries

University

10 Qs

2021_DASPRO_Pertemuan4

2021_DASPRO_Pertemuan4

University

10 Qs

Python Basics: Dictionaries and Strings

Python Basics: Dictionaries and Strings

Assessment

Quiz

Computers

University - Professional Development

Medium

Dictionaries, Strings

Standards-aligned

Created by

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

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?