#3.1
names=['lpr','tjl','gnl','by','dqy'];
print(names[0]);
print(names[1]);
print(names[2]);
print(names[3]);
print(names[4]); #3.2
print(names[0]+",Hello!");
print(names[1]+",Hello!");
print(names[2]+",Hello!");
print(names[3]+",Hello!");
print(names[4]+",Hello!"); #3.3
transport=['bike','high-way','bus','taxi','plane'];
print("I would like to own a "+transport[0]);
print("I would like to own a "+transport[1]);
print("I would like to own a "+transport[2]);
print("I would like to own a "+transport[3]);
print("I would like to own a "+transport[4]); #3.4
friends=['by','xdy','lyx'];
print("Hello,"+friends[0]+"! I would like to invent you to have dinner with me!");
print("Hello,"+friends[1]+"! I would like to invent you to have dinner with me!");
print("Hello,"+friends[2]+"! I would like to invent you to have dinner with me!"); #3.5
print(friends[1]+" cannot come here for dinner!");
friends[1]='dqy';
print("Hello,"+friends[0]+"! I would like to invent you to have dinner with me!");
print("Hello,"+friends[1]+"! I would like to invent you to have dinner with me!");
print("Hello,"+friends[2]+"! I would like to invent you to have dinner with me!"); #3.6
print("Hello,my friends!I have got a bigger desk for dinner just now,let's invent more 3 fridens!");
friends.insert(0,'lpr');
friends.insert(2,'nsx');
friends.append('gj');
print("Hello,"+friends[0]+"! I would like to invent you to have dinner with me!");
print("Hello,"+friends[1]+"! I would like to invent you to have dinner with me!");
print("Hello,"+friends[2]+"! I would like to invent you to have dinner with me!");
print("Hello,"+friends[3]+"! I would like to invent you to have dinner with me!");
print("Hello,"+friends[4]+"! I would like to invent you to have dinner with me!");
print("Hello,"+friends[5]+"! I would like to invent you to have dinner with me!"); #3.7
print("Sorry,I could only invent 2 friends for dinner!");
sorry=friends.pop();
print(sorry+",I am so sorry that you can't have dinner with me tonight!");
sorry=friends.pop();
print(sorry+",I am so sorry that you can't have dinner with me tonight!");
sorry=friends.pop();
print(sorry+",I am so sorry that you can't have dinner with me tonight!");
sorry=friends.pop();
print(sorry+",I am so sorry that you can't have dinner with me tonight!");
print("-----------------------------------------");
print(friends[-1]+",you can have dinner here,enjoy yourselves!");
print(friends[-2]+",you can have dinner here,enjoy yourselves!");
print("-----------------------------------------");
del friends[0];
del friends[0];
print(friends);
#3.8
dreamPlace=['Tokyo','Xiamen','Linzhi','London','Paris'];
print(dreamPlace);
#此处注意,sorted()函数的调用方式是把列表名作为参数传给sorted
print(sorted(dreamPlace));
print(sorted(dreamPlace,reverse=True));
#注意此处的reverse()函数的返回值不可以用变量接收
dreamPlace.reverse();
print(dreamPlace);
dreamPlace.reverse();
print(dreamPlace); dreamPlace.sort();
print(dreamPlace);
dreamPlace.sort(reverse=True);
print(dreamPlace); #3.9
print(dreamPlace[10]);

《Python编程:从入门到实践》第三章 列表简介 习题答案的更多相关文章

  1. #Python编程从入门到实践#第三章笔记

      列表简介 ​​​1.什么是列表 列表:由一系列按也顶顺序排列的元素组成.元素之间可以没有任何关系. 列表:用方括号[]表示,并用逗号分隔其中元素.名称一般为复数 2.访问元素 (1)列表是有序集合 ...

  2. Python:从入门到实践--第三章--列表简介--练习

    #1.将一些朋友的姓名存储在一个列表中,并将其命名为friends.依次访问该列表中的每个元素,从而将每个朋友的姓名都打印出来. #2.继续使用1中的列表,为每人打印一条消息,每条消息包含相同的问候语 ...

  3. #Python编程从入门到实践#第四章笔记

    #Python编程从入门到实践#第四章笔记   操作列表 ​​​1.遍历列表 使用for循环,遍历values列表 for value in values: print(value) 2.数字列表 使 ...

  4. 《Python编程从入门到实践》第二章_变量和简单数据类型

    什么是变量呢? 举例: >>> message = "Hello,Python!" >>> print (message) Hello,Pyth ...

  5. Python编程从入门到实践笔记——类

    Python编程从入门到实践笔记——类 #coding=gbk #Python编程从入门到实践笔记——类 #9.1创建和使用类 #1.创建Dog类 class Dog():#类名首字母大写 " ...

  6. 入门python:《Python编程从入门到实践》中文PDF+英文PDF+代码学习

    入门python推荐学习久负盛名的python入门书籍<Python编程从入门到实践>. 书中涵盖的内容是比较精简的,没有艰深晦涩的概念,最重要的是每个小结都附带有"动手试一试& ...

  7. 《Python编程:从入门到实践》分享下载

    书籍信息 书名:<Python编程:从入门到实践> 原作名:Python Crash Course 作者: [美] 埃里克·马瑟斯 豆瓣评分:9.1分(2534人评价) 内容简介 本书是一 ...

  8. Python编程从入门到实践笔记——异常和存储数据

    Python编程从入门到实践笔记——异常和存储数据 #coding=gbk #Python编程从入门到实践笔记——异常和存储数据 #10.3异常 #Python使用被称为异常的特殊对象来管理程序执行期 ...

  9. Python编程从入门到实践笔记——文件

    Python编程从入门到实践笔记——文件 #coding=gbk #Python编程从入门到实践笔记——文件 #10.1从文件中读取数据 #1.读取整个文件 file_name = 'pi_digit ...

随机推荐

  1. linux如何查看mysql是否启动

    linux下有很多服务,今天就写一下如何查看服务是否启动,以mysql为例子 使用命令 # service mysqld status 或者 # service mysql status 命令来查看m ...

  2. web端自动化——selenium Page Object设计模式

    Page Object设计模式的优点如下: ①    减少代码的重复. ②    提高测试用例的可读性. ③    提高测试用例的可维护性,特别是针对UI频繁变化的项目. 当为Web页面编写测试时,需 ...

  3. adb中文乱码问题怎么解决?

    1.chcp 65001      执行完命令后 2.在cmd命令弹出的终端页面,右键单击属性设置成字体Lucida Console ,设置完成就解决了 adb 中文乱码问题

  4. 安装Windows和Ubuntu双系统2

    安装Windows和Ubuntu双系统 0.552016.12.10 15:54:41字数 2101阅读 6644 这几天开始动手做毕设啦,打算好好过把Linux瘾,接下来便是这两天我在联想电脑上安装 ...

  5. 【Luogu P3919】可持久化数组

    数组是一种单点修改,单点查询的基础数据结构. 如果要对数组改进,使之可持久化,那么显然我们需要利用其它的数据结构来改进它. 对于单点修改和单点查询两种操作,很容易发现可持久化线段树也是支持这种操作的. ...

  6. 剪切板工具:Ditto

    DittoClipboard manager; 剪贴板工具https://ditto-cp.sourceforge.io/ 参考资料 https://www.liutf.com/posts/37207 ...

  7. Python3之字符串格式化format函数详解(下)

    格式限定符 format通过丰富的的“格式限定符”(语法是 {}中带:号)对需要格式的内容完成更加详细的制定. 进制转换 我们可以再限定符中制定不同的字符对数字进行进制转换的格式化,进制对应的表格: ...

  8. Struts笔记5

    文件下载 1.写action类 package com.gyf.web.action; import java.io.File; import java.io.FileInputStream; imp ...

  9. PAT(B) 1072 开学寄语(Java)统计

    题目链接:1072 开学寄语 (20 point(s)) 题目描述 下图是上海某校的新学期开学寄语:天将降大任于斯人也,必先删其微博,卸其 QQ,封其电脑,夺其手机,收其 ipad,断其 wifi,使 ...

  10. adb连接安卓设备的2种方式

    一.usb连接 安卓设备打开开发者模式,启用usb调试 CMD窗口输入adb devices,此时可以看到自己的设备 PS:无法看到自己设备时,查看手机USB调试是否打开:PC端是否安装手机驱动. 二 ...