#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. 线性回归:boston房价

    from sklearn.linear_model import LinearRegression,Lasso,Ridge from sklearn.datasets import load_bost ...

  2. python:动态参数*args

    动态参数 顾名思义,动态参数就是传入的参数的个数是动态的,可以是1个.2个到任意个,还可以是0个.在不需要的时候,你完全可以忽略动态函数,不用给它传递任何值. Python的动态参数有两种,分别是*a ...

  3. logstash kafka output 日志处理

    今天在用logstash解析日志并传送给kafka的时候,发现kafka能收到数据但数据内容已经丢失,具体如下: 在logstash output中增加输出样式之后,问题解决kafka再次接受到的内容 ...

  4. 【C/C++开发】C中调用C++函数

    C中如何调用C++函数? 前阵子被问及一个在C中如何调用C++函数的问题,当时简单回答是将函数用extern "C"声明,当被问及如何将类内成员函数声明时,一时语塞,后来网上查了下 ...

  5. c++ 在Ubuntu系统中使用access函数

    include<iostream> #include<stdlib.h> #include<stdio.h> #include<unistd.h> us ...

  6. Java中的IO流之输出流|乐字节

    大家好,乐字节小乐又来了.上一篇给大家带来的是:Java中的IO流之输入流|乐字节,本文将继续讲述IO流之输出流.   一.输出流 1.抽象类:OutputStream 和 Writer Output ...

  7. Qt 编译出错“undefined reference to `vtable for”

    1. 有时,如果将某个类改为继承自QObject类(以前不继承自该类),编译时会出错. 解决: clean Project, run qmake, rebulid都运行一遍,好了! 因为qmake生成 ...

  8. 036 Android Xutils3网络请求框架使用

    1.xUtils3 介绍 xUtils 中目前包括了主要的四大模块,分别为 DbUtils 模块.ViewUtils 模块.HttpUtils 模块以及 BitmapUtils 模块. xUtils3 ...

  9. [转帖]14-使用glusterfs做持久化存储

    14-使用glusterfs做持久化存储 https://www.cnblogs.com/guigujun/p/8366558.html 使用glusterfs做持久化存储 我们复用kubernete ...

  10. [WinForm] - 关闭应用时 "has stopped working" 之解决

    背景 关闭 WinForm 应用出现 "has stopped working" 错误. Windows 日志 Faulting application name: PcClien ...