《Python编程:从入门到实践》第三章 列表简介 习题答案
#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编程:从入门到实践》第三章 列表简介 习题答案的更多相关文章
- #Python编程从入门到实践#第三章笔记
列表简介 1.什么是列表 列表:由一系列按也顶顺序排列的元素组成.元素之间可以没有任何关系. 列表:用方括号[]表示,并用逗号分隔其中元素.名称一般为复数 2.访问元素 (1)列表是有序集合 ...
- Python:从入门到实践--第三章--列表简介--练习
#1.将一些朋友的姓名存储在一个列表中,并将其命名为friends.依次访问该列表中的每个元素,从而将每个朋友的姓名都打印出来. #2.继续使用1中的列表,为每人打印一条消息,每条消息包含相同的问候语 ...
- #Python编程从入门到实践#第四章笔记
#Python编程从入门到实践#第四章笔记 操作列表 1.遍历列表 使用for循环,遍历values列表 for value in values: print(value) 2.数字列表 使 ...
- 《Python编程从入门到实践》第二章_变量和简单数据类型
什么是变量呢? 举例: >>> message = "Hello,Python!" >>> print (message) Hello,Pyth ...
- Python编程从入门到实践笔记——类
Python编程从入门到实践笔记——类 #coding=gbk #Python编程从入门到实践笔记——类 #9.1创建和使用类 #1.创建Dog类 class Dog():#类名首字母大写 " ...
- 入门python:《Python编程从入门到实践》中文PDF+英文PDF+代码学习
入门python推荐学习久负盛名的python入门书籍<Python编程从入门到实践>. 书中涵盖的内容是比较精简的,没有艰深晦涩的概念,最重要的是每个小结都附带有"动手试一试& ...
- 《Python编程:从入门到实践》分享下载
书籍信息 书名:<Python编程:从入门到实践> 原作名:Python Crash Course 作者: [美] 埃里克·马瑟斯 豆瓣评分:9.1分(2534人评价) 内容简介 本书是一 ...
- Python编程从入门到实践笔记——异常和存储数据
Python编程从入门到实践笔记——异常和存储数据 #coding=gbk #Python编程从入门到实践笔记——异常和存储数据 #10.3异常 #Python使用被称为异常的特殊对象来管理程序执行期 ...
- Python编程从入门到实践笔记——文件
Python编程从入门到实践笔记——文件 #coding=gbk #Python编程从入门到实践笔记——文件 #10.1从文件中读取数据 #1.读取整个文件 file_name = 'pi_digit ...
随机推荐
- SourceTree 免登录跳过初始设置的方法 for Windows
SourceTree安装包下载地址: 链接: https://pan.baidu.com/s/1rOPQkfNqvLGcIeZNw0aAjw 密码: 42us nodev6.9.0 和git 链接:h ...
- 使用第三方Java类库jaudiotagger完成Flac音频文件metadata(元数据)的读和修改
最近需要使用Java Swing做个读写Flac格式音频文件的小GUI工具,虽然Mp3tag完全可以完成Flac的读写(编辑)任务,但是为了简化工作流程(编辑Flac信息后调用其它系统的接口完成部分信 ...
- VMware虚拟机及Linux安装
VMware虚拟机安装指南:http://bbs.luobotou.org/thread-5750-1-1.html Linux系统各发行版镜像下载地址:http://www.linuxidc.com ...
- FutureTask源码阅读
FutureTask功能用法 类结构 源码中详细说明了FutureTask生命周期状态及变化 /** * The run state of this task, initially NEW. The ...
- Chipseq数据库的建立
这里以小鼠为例子下载相应的注释文件,基因组版本为mm10 下载refGene.txt.gz 网址:http://hgdownload.cse.ucsc.edu/goldenPath/mm10/data ...
- linux ubuntu 网卡配置---固定IP
需要修改/etc/network/interfaces和/etc/resolvconf/resolv.conf.d/base两个文件. 1) /etc/network/interfaces文件: 首先 ...
- Deepin 15.11 install nvidia dirver[mei you an zhuang shu ru fa]
1.firstly, exec: sudo vim /etc/modprobe.d/blacklist-nouveau.conf[create], and input [blacklist nouve ...
- Spyder中报错: Check failed: PyBfloat16_Type.tp_base != nullptr
报错问题: 问题1:tensorflow/python/lib/core/bfloat16.cc:675] Check failed: PyBfloat16_Type.tp_base != nullp ...
- Python17之函数、类、模块、包、库
一.函数 一个拥有名称.参数和返回值的代码块. 需要主动调用,否则不会执行,可以通过参数和返回值与其它程序进行交互 二.类 用来描述具有相同的属性和方法的对象集合.它定义了该集合中每个对象所共有的属性 ...
- PHP中的PDO数据对象
PDO: PHP Data Object:php的数据对象.pdo是数据库操作工具类!1,它能操作很多种数据库,比如mysql,oracle,sybase....2,它具有操作数据库的更多的功能,比如 ...