#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. JAVA视频压缩

    https://www.cnblogs.com/chuanyueinlife/p/9014627.html

  2. Spring Boot系列之-helloword入门

    一. What: Spring Boot是什么?以1.4.3.RELEASE为例,官方介绍为:http://docs.spring.io/spring-boot/docs/1.4.3.RELEASE/ ...

  3. 【Leetcode_easy】1137. N-th Tribonacci Number

    problem 1137. N-th Tribonacci Number solution: class Solution { public: int tribonacci(int n) { ) ; ...

  4. 常见浏览器CSS hack方法总结

    ie6和ie7 #tip {*background:black; /*IE7 背景变黑色*/_background:orange; /*IE6 背景变橘色*/} IE8和IE9 :root .test ...

  5. requests-html调用浏览器内核界面化源码改动

    在实例化HTMLSession时传入参数:headless=False即可在r.html.render()时显示界面化的浏览器

  6. 配置Hive数据仓库

    1.在线安装mysql服务 #下载安装mysql yum install mysql mysql-server mysql-devel #启动mysql服务 cd /etc/ init.d/mysql ...

  7. shell sed -i 指定内容追加.

    1.查看原文件中的内容 [root@testvm02 ~]# cat nrpe.cfg #command[check_users]=/usr/local/nagios/libexec/check_us ...

  8. mysql数据库,数据表,数据的增删查改语句

    查询mysql支持的引擎 show engines; 查询mysql支持的字符集 show character set; 设置mysql默认存储引擎 set default_storage_engin ...

  9. vue导入css,js和放置html代码

    使用场景:我是从网上找的html前端页面模板,导入找的模板中的css和js到vue中使用. 1.在main.js中全局导入css和js import '@/assets/css/main.css' i ...

  10. 列主元消去法&全主元消去法——Java实现

    Gauss.java package Gauss; /** * @description TODO 父类,包含高斯列主元消去法和全主元消去法的共有属性和方法 * @author PengHao * @ ...