- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
Introduction to Computer Programming.ppt
2.3 List (4) Adding elements Method 1: Use the “+” to attach a new list in the tail of a original list a_list = [1] a_list = a_list + [a, 2.0] a_list [1, a, 2.0 ] Method 2: Uses append () method to add a new element to the end of a list; a_list.append(True) a_list [1, a, 2.0, True ] 2.3 列表 (4)增加元素 方法一:使用“+”将一个新列表附加在原列表的尾部; a_list = [1] a_list = a_list + [a, 2.0] a_list [1, a, 2.0] 方法二:使用append( )方法向列表尾部添加一个新元素; a_list.append(True) a_list [1, a, 2.0, True] 2.3 List Method 3: Use the extend () method to add a list at the tail of the original list; a_list.extend([x, 4]) a_list [1, a, 2.0, True, x, 4 ] Method 4: Use the insert () method to add an element into the list anywhere. a_list.insert(0, x) a_list [x, 1, a, 2.0, True, x, 4] 2.3 列表 方法三:使用extend( )方法将一个列表添加在原列表的尾部; a_list.extend([x, 4]) a_list [1, a, 2.0, True, x, 4] 方法四:使用insert( )方法将一个元素插入到列表的任意位置。 a_list.insert(0, x) a_list [x, 1, a, 2.0, True, x, 4] 2.3 List (5) Search Use count ( ) method to calculate the number of an element in the list; a_list.count(x) 2 Use ”in” Operator checking whether an element is in the list; 3 in a_list False 2.0 in a_list True a_list = [x, 1, a, 2.0, True, x, 4] 2.3 列表 (5)检索元素 使用count( )方法计算列表中某个元素出现的次数; a_list.count(x) 2 使用in运算符返回某个元素是否在该列表中; 3 in a_list False 2.0 in a_list True 2.3 列表 Use the index () method to return the exact location of an element in the list; 使用index()方法返回某个元素在列表中的准确位置; a_list.index(x) 0 a_list.index(5) Traceback (most recent call last): File pyshell#33, line 1, in module a_list.index(5) ValueError: 5 is not in list a_list = [x, 1, a, 2.0, True, x, 4] 2.3 List (6) Delete an element ????When adding or removing elements, the list will automatically expand or shrink. The list will never have gaps. Method 1: Use the “del” statement to delete the elements at a particular location del a_list[1] a_list [x, a, 2.0, True, x, 4] a_list = [x, 1, a, 2.0, True, x, 4] 2.3 列表 (6)删除元素 当向列表中添加或删除元素时,列表将自动拓展或收缩,列表中永远不会有缝隙。 方法一
您可能关注的文档
- Data Structures.ppt
- Day-to-Day Management of Public Funds and Investment Rep.ppt
- Developing an integrated teaching workforce a Universit.ppt
- Diversification Strategy.ppt
- Dividend Policy.ppt
- Do You Speak the Other Guy's Language Culture, Diversit.ppt
- Document SystemsValidation.ppt
- Doing Business in Italy (Luxury, Fashion & Design)B8631.ppt
- Dr Marie-Christine GasingirwaDG Science, Technologie et.ppt
- East View 俄罗斯大全数据库特色与主要功能介绍.ppt
- Introduction toOperations Management.ppt
- Introduction Valuation and Course Goals.ppt
- INTRODUCTION.ppt
- ISMT 200g (Feb 6, 2007 Lecture) “The Art of War” in Bus.ppt
- IT Ed A Way Forward.ppt
- IT专业的职业方向.ppt
- j5hsizbippt.ppt
- Joint JapanWorld Bank Graduate Scholarship Program offe.ppt
- kejian17ppt.ppt
- L'enseignement à distance appliqué à la formation contin.ppt
文档评论(0)