python实例 列表
#! /usr/bin/python
# -*- coding: utf8 -*-
#列表类似Javascript的数组,方便易用
#定义元组
word=['a','b','c','d','e','f','g']
#如何通过索引访问元组里的元素
a=word[2]
print ("a is: "+a)
b=word[1:3]
print ("b is: ")
print (b) # index 1 and 2 elements of word.
c=word[:2]
print ("c is: ")
print (c) # index 0 and 1 elements of word.
d=word[0:]
print ("d is: ")
print (d) # All elements of word.
#元组可以合并
e=word[:2]+word[2:]
print ("e is: ")
print (e) # All elements of word.
f=word[-1]
print ("f is: ")
print (f) # The last elements of word.
g=word[-4:-2]
print ("g is: ")
print (g) # index 3 and 4 elements of word.
h=word[-2:]
print ("h is: ")
print (h) # The last two elements.
i=word[:-2]
print ("i is: ")
print (i) # Everything except the last two characters
l=len(word)
print ("Length of word is: "+ str(l))
print ("Adds new element")
word.append('h')
print (word)
#删除元素
del word[0]
print (word)
del word[1:3]
print (word)
'''
知识点:
* 列表长度是动态的,可任意添加删除元素.
* 用索引可以很方便访问元素,甚至返回一个子列表
* 更多方法请参考Python的文档
'''
python实例 列表的更多相关文章
- python中列表元素连接方法join用法实例
python中列表元素连接方法join用法实例 这篇文章主要介绍了python中列表元素连接方法join用法,实例分析了Python中join方法的使用技巧,非常具有实用价值,分享给大家供大家参考. ...
- 对Python中列表和数组的赋值,浅拷贝和深拷贝的实例讲解
引用:https://www.jb51.net/article/142775.htm 列表赋值: 1 2 3 4 5 6 7 >>> a = [1, 2, 3] >>&g ...
- 【Python 实例】面向对象 | 按逗号分割列表
[Python 实例]面向对象 | 按逗号分割列表 题目: 按逗号分割列表 应该得到如下结果: ["xx"],["xx"],["xx"] 解 ...
- 【Python 实例】面向对象 | 按相反的顺序输出列表的值
[Python 实例]面向对象 | 按相反的顺序输出列表的值 题目: 解答: 运行结果: 题目: 按相反的顺序输出列表的值 解答: """ 按相反的顺序输出列表的值 &q ...
- (转)Python实例手册
原文地址:http://hi.baidu.com/quanzhou722/item/cf4471f8e23d3149932af2a7 实在是太好的资料了,不得不转 python实例手册 #encodi ...
- Python统计列表中的重复项出现的次数的方法
本文实例展示了Python统计列表中的重复项出现的次数的方法,是一个很实用的功能,适合Python初学者学习借鉴.具体方法如下:对一个列表,比如[1,2,2,2,2,3,3,3,4,4,4,4],现在 ...
- 转载 python实例手册
python实例手册 #encoding:utf8# 设定编码-支持中文 0说明 手册制作: 雪松 更新日期: 2013-12-19 欢迎系统运维加入Q群: 198173206 # 加群请回答问题 请 ...
- python基础——列表
Python列表脚本操作符 列表对 + 和 * 的操作符与字符串相似.+ 号用于组合列表,* 号用于重复列表. 如下所示: Python 表达式 结果 描述 len([1, 2, 3]) 3 长度 [ ...
- 【转】Python之列表生成式、生成器、可迭代对象与迭代器
[转]Python之列表生成式.生成器.可迭代对象与迭代器 本节内容 语法糖的概念 列表生成式 生成器(Generator) 可迭代对象(Iterable) 迭代器(Iterator) Iterabl ...
随机推荐
- HTTP的九种请求方法
HTTP1.0定义了三种请求方法:GET.POST.HEAD HTTP1.1定义了六种请求方法:PUT.DELETE.PATCH.OPTIONS.CONNECT.TRACE 1.get 请求指定页面的 ...
- IntelliJ IDEA community 安装教程
jetbrains官网下载 IntelliJ IDEA安装包 https://www.jetbrains.com/idea/download/#section=windows 此处选择社区版的zip文 ...
- vue生成条形码/二维码/带logo二维码
条形码:https://blog.csdn.net/dakache11/article/details/83749410 //安装 cnpm install @xkeshi/vue-barcode / ...
- WebSockets
WebSocket 是为了在一个单独的持久连接上提供全双工的双向通信.有关WebSocket API的内容可以参考这里. 这里简单说明下WebSocket在javascript中的用法. 1 WebS ...
- C#端一个不错的订单号生成规则
/// <summary> /// 订单助手 /// </summary> public class OrderHelper { /// <summary> /// ...
- Windows API 第21篇 DeleteVolumeMountPoint 删除挂载点
函数原型:BOOL DeleteVolumeMountPoint( LPCTSTR lpszV ...
- jiba中文分词原理
中文分词就是将一个汉字序列分成一个一个单独的词. 现有的分词算法有三大类: 基于字符串匹配的分词:机械分词方法,它是按照一定的策略将待分析的字符串与一个充分大的机器词典中的词条进行匹配,若在词典中找到 ...
- UVA - 1230
https://vjudge.net/problem/UVA-1230 费马小定理优化快速幂 #include <iostream> #include <cstdio> #in ...
- Python_day01——字符串
https://www.cnblogs.com/A-FM/p/5691468.html def main(): str1 = 'hello, world!' # 通过len函数计算字符串的长度 # 获 ...
- Python3.5 安装 & hello world
1.下载安装python https://www.python.org/downloads/release/python-364/ 2.安装成功运行 python shell 3.或者cmd => ...