#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. 原生JavaScript常用本地浏览器存储方法五(LocalStorage+userData的一个浏览器兼容类)

    基于LocalStorage+globalStorage+userData实现的一个本地存储类 userData用来兼容ie6 ie7 由userData模仿Session的方法:浏览器关闭删除保存的 ...

  2. STM32驱动模数转换芯片ADS1120(基础知识篇)第1篇

    1. 先看下ADS1120的结构图,ADS1120是个比较奇葩的ADC模数转换器,因为比较适用于热电阻之类的温度采集器.看下图,有个MUX多路复用器,应该是选择两个差分信号去测试,通过输入多路复用器 ...

  3. intel 蓝牙驱动安装时报错

    BT_20.120.2_64_Win7.exe 安装时报错. 把系统补丁打全,就可以安装 了.

  4. 最新 企叮咚java校招面经 (含整理过的面试题大全)

    从6月到10月,经过4个月努力和坚持,自己有幸拿到了网易雷火.京东.去哪儿. 企叮咚等10家互联网公司的校招Offer,因为某些自身原因最终选择了 企叮咚.6.7月主要是做系统复习.项目复盘.Leet ...

  5. qt qml Treeview使用记录--设置每个Item的图片logo,高度

    这篇帮助很大: https://blog.csdn.net/qq_32116695/article/details/81298585, 代码如下: TreeView { id: viewTree an ...

  6. Cookies和Sessions

    Cookie和Session 为什么会有cookie和session? 由于http协议是无状态的 无法记住用户是谁,cookie主要是在浏览器上记录客户的状态,session主要是用来在服务端记录客 ...

  7. 在 VMware 中安装 MacOS 全记录

    在 VMware 15 中安装 MacOS Mojave 安装文件 下载:Unlocker v3.0 for VMware 15地址:https://github.com/DrDonk/unlocke ...

  8. [C++] 二叉树计算文件单词数

    目录 前置技能 构造和遍历二叉树 文件的打开.读取和写入 需求描述 读取文件 构建二叉树 格式化输入输出 具体实现 main.cpp binarytree.h binarytree.cpp 使用二叉树 ...

  9. qt 旧项目编译运行提示 “启动程序失败,路径或者权限错误?” 原因及解决方法

    qt 旧项目编译运行提示 "启动程序失败,路径或者权限错误?" 原因及解决方法 原因 Qt Creator在打开项目文件的同时会生成.pro.user文件,.pro.user文件叫 ...

  10. Istio技术与实践6:Istio如何为服务提供安全防护能力

    凡是产生连接关系,就必定带来安全问题,人类社会如此,服务网格世界,亦是如此. 今天,我们就来谈谈Istio第二主打功能---保护服务. 那么,便引出3个问题: l  Istio凭什么保护服务? l  ...