#!/usr/bin/python
word=['a','b','c','d','e','f','g']
# 取第二个元素
a=word[2]
print "a is: "+a
# 取第2~3个元素
b=word[1:3]
print "b is: "
print b
# 取前2个元素
c=word[:2]
print "c is: "
print c
# 取所有元素
d=word[0:]
print "d is: "
print d
# 同上
e=word[:2]+word[2:]
print "e is: "
print e
# 取最后一个元素
f=word[-1]
print "f is: "
print f
# 取倒数第4~3个元素
g=word[-4:-2]
print "g is: "
print g
# 取最后2个元素
h=word[-2:]
print "h is: "
print h
# 取除最后2个元素之外的元素
i=word[:-2]
print "i is: "
print i
# 取其长度
l=len(word)
print "Length of word is: "+ str(l)
print "Adds new element"
# 追加元素
word.append('h')
print word
# 追加(合并)列表
word.extend(['a', 'b'])
print word
相关文章
- java如何取出list的最后一个值,如何从Java中的ArrayList获取第一个和最后一个元素?...
- 将一个list中的元素的某一属性取出来单独放到一个list/map里面
- java中List集合三种获取集合元素方式
- python中list列表删除元素的4种方法
- python中list列表修改元素
- C#---第十四课:数组(Array)& 列表(List)增删元素、按字母排序、拼接、去重
- 从list集合中取某一个属性值操作
- C# list常用的几个操作 改变list中某个元素的值 替换某一段数据
- java中removeif用法,java中List集合 removeIf方法删除符合条件的元素
- Java中对List集合内的元素进行顺序、倒序、随机排序的示例代码