Chapter 10 Quiz

10 试题

1.

What is the difference between a Python tuple and Python list?

Lists are mutable and tuples are not mutable

Lists maintain the order of the items and tuples do not maintain order

Tuples can be expanded after they are created and lists cannot

Lists are indexed by integers and tuples are indexed by strings

2.

Which of the following methods work both in Python lists and Python tuples?

pop()

index()

sort()

reverse()

append()

3.

What will end up in the variable y after this code is executed?

x , y = 3, 4

A two item tuple

3

4

A dictionary with the key 3 mapped to the value 4

A two item list

4.

In the following Python code, what will end up in the variable y?

x = { 'chuck' : 1 , 'fred' : 42, 'jan': 100}
y = x.items()

A list of strings

A list of tuples

A list of integers

A tuple with three integers

5.

Which of the following tuples is greater than x in the following Python sequence?

x = (5, 1, 3)
if ??? > x :...

(6, 0, 0)

(5, 0, 300)

(0, 1000, 2000)

(4, 100, 200)

6.

What does the following Python code accomplish, assuming the c is a non-empty dictionary?

tmp = list()
for k, v in c.items() :tmp.append( (v, k) )

It computes the largest of all of the values in the dictionary

It computes the average of all of the values in the dictionary

It sorts the dictionary based on its key values

It creates a list of tuples where each tuple is a value, key pair

7.

If the variable data is a Python list, how do we sort it in reverse order?

data.sort(reverse=True)

data.sort.reverse()

data = sortrev(data)

data = data.sort(-1)

8.

Using the following tuple, how would you print 'Wed'?

days = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')

print days[2]

print days{2}

print days(2)

print days[1]

print days.get(1,-1)

9.

In the following Python loop, why are there two iteration variables (k and v)?

c = {'a':10, 'b':1, 'c':22}
for k, v in c.items() :...

Because the items() method in dictionaries returns a list of tuples

Because for each item we want the previous and current key

Because there are two items in the dictionary

Because the keys for the dictionary are strings

10.

Given that Python lists and Python tuples are quite similar - when might you prefer to use a tuple over a list?

For a list of items you intend to sort in place

For a list of items that want to use strings as key values instead of integers

For a list of items that will be extended as new items are found

For a temporary variable that you will use and discard without modifying

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

  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. maven的setting.xml文件配置信息【仅仅更改了一处】
  2. 使用Ptrace跟踪进程收到的异常信号(信号SIGTRAP是通过traceme后wait得到的)
  3. c++精确到小数点后两位_高考试卷的小数点是怎么算入总分的?
  4. Vue指令之v-model和双向数据绑定
  5. 【2019暑假刷题笔记-树的遍历】总结
  6. spring boot使用外置tomcat部署需要排除的依赖
  7. java tostring 库_java重寫toString()方法
  8. VS2010关于更改管理帮助设置的路径的解决方案
  9. python文件路径改了需要重新配置环境吗_python自学环境配置
  10. Python基础-程序控制结构
  11. HBase完全分布式集群部署
  12. 【转】扫盲 同步利器、分布式网盘--BT Sync
  13. 使用奇妙清单:轻松搞定家庭计划事项同步管理
  14. 刀剑神域:突破界限I
  15. 主成分分析结果成分不显著_主成分分析结果
  16. 【华人学者风采】丛京生 加州大学洛杉矶分校
  17. 免登录采集淘宝商品详情的方法
  18. 91文件夹操作——创建和删除多级目录
  19. 简历之精通 熟练 掌握 熟悉 了解
  20. 更新hdf之后无法找到接口映射

热门文章

  1. 美团点评业务风控系统构建经验
  2. 教程 | 理解和实现自然语言处理终极指南(附Python代码)
  3. 国家卫计委倡导健康生活理念:每天发呆5分钟
  4. RocketMQ-初体验RocketMQ(04)_使用RocketMQ Console源码搭建RocketMQ Console与基本使用
  5. ORACLE-WITH 子句详解
  6. java抢答器代码_java竞争抢答器
  7. Android之----Log详解(Log.v,Log.d,Log.i,Log.w,Log.e)
  8. 双代号网络图节点编号原则_一表多图(表格/横道图/网络图)让计划编制效率提高10倍...
  9. numpy.lib.stride_tricks.as_strided() 高效切分数组
  10. 老旧计算机升级云桌面,哇哦!PC机房轻松升级云课堂 ,PC利旧方案看我的!