Chapter 9 Quiz

10 试题

1.

How are Python dictionaries different from Python lists?

Python lists maintain order and dictionaries do not maintain order

Python lists can store strings and dictionaries can only store words

Python dictionaries are a collection and lists are not a collection

Python lists store multiple values and dictionaries store a single value

2.

What is a term commonly used to describe the Python dictionary feature in other programming languages?

Lambdas

Sequences

Associative arrays

Closures

3.

What would the following Python code print out?

stuff = dict()
print stuff['candy']

0

-1

The program would fail with a traceback

candy

4.

What would the following Python code print out?

stuff = dict()
print stuff.get('candy',-1)

0

-1

'candy'

The program would fail with a traceback

5.

(T/F) When you add items to a dictionary they remain in the order in which you added them.

False

True

6.

What is a common use of Python dictionaries in a program?

Building a histogram counting the occurrences of various strings in a file

Splitting a line of input into words using a space as a delimiter

Computing an average of a set of numbers

Sorting a list of names into alphabetical order

7.

Which of the following lines of Python is equivalent to the following sequence of statements assuming that counts is a dictionary?

if key in counts:counts[key] = counts[key] + 1
else:counts[key] = 1

counts[key] = (key in counts) + 1

counts[key] = counts.get(key,-1) + 1

counts[key] = (counts[key] * 1) + 1

counts[key] = key + 1

counts[key] = counts.get(key,0) + 1

8.

In the following Python, what does the for loop iterate through?

x = dict()
...
for y in x :...

It loops through all of the dictionaries in the program

It loops through the integers in the range from zero through the length of the dictionary

It loops through the keys in the dictionary

It loops through the values in the dictionary

9.

Which method in a dictionary object gives you a list of the values in the dictionary?

items()

keys()

each()

all()

values()

10.

What is the purpose of the second parameter of the get() method for Python dictionaries?

The value to retrieve

To provide a default value if the key is not found

The key to retrieve

An alternate key to use if the first key cannot be found

Coursera课程Python for everyone:chapter9相关推荐

  1. Coursera课程Python for everyone:Quiz: Many-to-Many Relationships and Python

    Many-to-Many Relationships and Python 9 试题

  2. Coursera课程Python for everyone:Quiz: Multi-Table Relational SQL

    Multi-Table Relational SQL 10 试题 1. What is the primary added value of relational databases over fla ...

  3. Coursera课程Python for everyone:Quiz: Single-Table SQL

    Single-Table SQL 11 试题 1. Structured Query Language (SQL) is used to (check all that apply) Delete d ...

  4. Coursera课程Python for everyone:Quiz: Object Oriented Programming

    Object Oriented Programming 11 试题 1. Which came first, the instance or the class? instance class fun ...

  5. Coursera课程Python for everyone:Quiz: REST, JSON, and APIs

    REST, JSON, and APIs 10 试题 1. Who is credited with getting the JSON movement started? Pooja Sankar M ...

  6. Coursera课程Python for everyone:Quiz: eXtensible Markup Language

    eXtensible Markup Language 10 试题 1. What is "serialization" when we are talking about web ...

  7. Coursera课程Python for everyone:Quiz: Reading Web Data From Python

    Reading Web Data From Python 8 试题 1. Which of the following Python data structures is most similar t ...

  8. Coursera课程Python for everyone:Quiz: Networks and Sockets

    Networks and Sockets 10 试题 1. What do we call it when a browser uses the HTTP protocol to load a fil ...

  9. Coursera课程Python for everyone:Quiz: Regular Expressions

    Quiz: Regular Expressions 10 试题 1. Which of the following best describes "Regular Expressions&q ...

最新文章

  1. k8s使用kube-router网络插件并监控流量状态
  2. vmware virtualization software
  3. 前端:前端安全编码规范
  4. ad域管理与维护_在NAS SMB卷上使用VisualSVN Server维护代码库
  5. 容器编排技术 -- Kubernetes 为 Namespace 配置CPU和内存配额
  6. rails_Rails应用程序必备的宝石
  7. android系统功耗优化(2)---Android最佳实践之性能 - 电池续航时间优化
  8. git管理github仓库详解
  9. 极简代码(三)—— 向量加法
  10. 企业软件是最难编写的软件
  11. 使用python实现深度神经网络--学习笔记
  12. WNM6002 N通道增强功能MOS场效应晶体管
  13. linux命令行里输入nyancat,好玩的Linux命令行,与彩虹猫Nyan Cat一起休息下
  14. wps实现冻结首行的方法
  15. 你在百度区块链养狗了么?
  16. discuz的css文件在哪里,谁能告诉我discuz模板文件在哪个文件夹下?
  17. QuickCHM V2.6
  18. Vistual Studio Community 2017 30天许可证过期
  19. Smartbanner: Intelligent banner design framework that strikes a balance between freedom and rules
  20. 运维与Python之间有着怎样的联系?

热门文章

  1. 银河麒麟4安装MySQL8_2020-03-24 linux 安装mysql8.0
  2. Java - Jackson JSON Java Parser API
  3. APM - Javassist 入门 生成一个简单类
  4. 爬虫学习笔记(九)—— Scrapy框架(四):FormRequest、日志
  5. Android中finish()、System.exit()、KillProcess()的区别
  6. php 文件夹里有多少,计算目录php中有多少个文件
  7. access窗体中再制作查询窗体_如何给java窗体添加下拉菜单项,以选择游戏难度为例 - 攻向前端的小白...
  8. idea插件Easy Code的使用
  9. 异常:catch下的return;
  10. vue 表格内容跳转页面_Vue项目实战系列文章(一)项目预热