当前位置: 首页 > news >正文

给网站写教案做课件一节课多少钱/公司网站设计要多少钱

给网站写教案做课件一节课多少钱,公司网站设计要多少钱,全球十大设计公司,网页设计插入图片居中1.说出两种创建包含了5个整数0的列表的方法。 答:一个字面量(literal)表达式如 [0, 0, 0, 0, 0] 和一个重复(repetition)表达式如 [0] * 5 每个可以创建5个0的列表。事实上,你可以用一个空列表 [] &#xf…

1.说出两种创建包含了5个整数0的列表的方法。
答:一个字面量(literal)表达式如 [0, 0, 0, 0, 0] 和一个重复(repetition)表达式如 [0] * 5 每个可以创建5个0的列表。事实上,你可以用一个空列表 [] ,然后建立起循环,每次迭代附加(append)一个0,使用语句 L.append(0)。一个列表推导式([0 for i in range(5)])在这也能起作用,但这比你为这个答案所需要做的工作还要多。

 

2.说出两种创建有两个键(键'a', 'b',每个相关的值都是0)的字典的方法。
答:一个字面量(literal)表达式如 {'a': 0, 'b': 0} 或者一系列的赋值操作如 D = {}, D['a'] = 0 以及 D['b'] = 0 将创建你预期的字典。你当然可以使用更新颖和更容易编写的 dict(a=0, b=0) 关键字形式,或者更灵活的 dict([('a', 0), ('b', 0)]) 键/值序列形式。或者,因为所有的值是相等的,你可以使用特殊形式 dict.fromkeys('ab', 0)。在Python 3.X 和 2.7 中,你可以使用一个字典推导式:{k:0 for k in 'ab'} ,不过,这可能有点过头了。

 

3.说出四种改变列表对象的操作。
答:append 和 extend 方法可以使列表增长(grow),sort 和 reverse 方法可以排序和反转列表,insert 方法能以某个偏移量(offset)把项(item)插入列表中,remove 和 pop 方法按值和位置从列表中删除,del 语句可以删除一个对象或者切片,而且索引和切片赋值语句可以取代一个对象或者整个部分。对于这个问题,可以从上述中任意挑选四种方式来回答。

 

4.说出四种改变字典对象的操作。
答:字典主要是通过分配给新的或现有的键来更改的,这会创建或更改表中的键条目。而且,del 语句删除键的条目,字典 update 方法把一个字典就地融合到另一个字典中,D.pop(key) 移除一个键然后返回它对应的值。字典中也有其他更奇异的改变方法在本章中没有介绍,例如 setdefault ;查看参考资源来获取更多细节。

 

5.为什么你可以用字典取代列表?
答:当数据被打上标签(例如,带有字段名【field name】的记录),字典通常表现地更好;列表最好适用于没有打上标签的项的集合(例如,文件目录中所有的文件)。字典查找通常也比搜索列表更快,尽管这可能因程序而异。

 

标注:转载《Learning Python 5th Edition》[奥莱理]

1. Name two ways to build a list containing five integer zeros.
2. Name two ways to build a dictionary with two keys, 'a' and 'b', each having an associated value of 0.
3. Name four operations that change a list object in place.
4. Name four operations that change a dictionary object in place.
5. Why might you use a dictionary instead of a list?

1. A literal expression like [0, 0, 0, 0, 0] and a repetition expression like [0] * 5 will each create a list of five zeros. In practice, you might also build one up with a loop that starts with an empty list and appends 0 to it in each iteration, with L.append(0). A list comprehension ([0 for i in range(5)]) could work here, too, but this is more work than you need to do for this answer.
2. A literal expression such as {'a': 0, 'b': 0} or a series of assignments like D = {}, D['a'] = 0, and D['b'] = 0 would create the desired dictionary. You can also use the newer and simpler-to-code dict(a=0, b=0) keyword form, or the more flexible dict([('a', 0), ('b', 0)]) key/value sequences form. Or, because all the values are the same, you can use the special form dict.fromkeys('ab', 0). In 3.X and 2.7, you can also use a dictionary comprehension: {k:0 for k in 'ab'}, though again, this may be overkill here.
3. The append and extend methods grow a list in place, the sort and reverse methods order and reverse lists, the insert method inserts an item at an offset, the remove and pop methods delete from a list by value and by position, the del statement deletes an item or slice, and index and slice assignment statements replace an item or entire section. Pick any four of these for the quiz.
4. Dictionaries are primarily changed by assignment to a new or existing key, which creates or changes the key’s entry in the table. Also, the del statement deletes a key’s entry, the dictionary update method merges one dictionary into another in place, and D.pop(key) removes a key and returns the value it had. Dictionaries also have other, more exotic in-place change methods not presented in this chapter, such as setdefault; see reference sources for more details.
5. Dictionaries are generally better when the data is labeled (a record with field names, for example); lists are best suited to collections of unlabeled items (such as all the files in a directory). Dictionary lookup is also usually quicker than searching a list, though this might vary per program.

http://www.lbrq.cn/news/1443133.html

相关文章:

  • 如何防止php网站被挂马/厦门seo
  • 已有网站如何做直播/黑帽seo寄生虫
  • 做海报找背景图有哪些网站/全球搜索
  • php发布post到wordpress/百度seo优
  • 政府网站手机版建设方案/推广一单500
  • 做网站劫持多少钱/做个网站
  • 网页微博如何退出登录/网站的优化公司
  • 广州市地铁线路最新全图/在线seo超级外链工具
  • crm系统是干什么的/廊坊seo排名外包
  • 网上商城项目设计方案/郑州seo网站有优化
  • 动易网站首页制作/最全的搜索引擎
  • 建电影网站教程/百度统计登录
  • 企业网站建设遵循的原则/网店运营流程步骤
  • 廊坊建站模板系统/广告推广方案
  • 在线考试类网站怎么做/百度网盘官网下载
  • 海淀网站建设联系方式/关键词排名优化流程
  • 做网站办公照片/百度视频推广怎么收费
  • 网站建设关键字/网站seo课程
  • 网站首页滚动图片用dw怎么做/国外独立网站如何建站
  • 服务型网站有哪些/友情链接网自动收录
  • 西安做网站的/百度官方网页
  • 网站宣传页/上海百度关键词优化公司
  • 河北斯皮尔网站建设/舆情网站直接打开
  • 镇江有哪些网站/个人接app推广单去哪里接
  • 建设银行宁德分行网站/seo网站内部优化
  • 建立独立网站/泰安网站seo
  • 海报设计 网站/百度人工客服24小时电话
  • 网站开发环境与工具/百度百家号登录入口
  • html5动态网站模板/seo关键字优化
  • 电力建设工程质监总站网站/江苏免费关键词排名外包
  • web前端第二次作业
  • 【论文阅读】从表面肌电信号中提取神经信息用于上肢假肢控制:新兴途径与挑战
  • 机器学习算法篇(十):TF-IDF算法详解与应用实战
  • Redis 数据结构及特点
  • 5G与云计算对代理IP行业的深远影响
  • 嵌入式硬件中AI硬件设计方法与技巧