list

print "append"
lst = [1, 2,3]
lst.append(4)
print lst

print "count"
print ['to', 'be', 'or', 'not', 'to', 'be'].count('to')

print "extend"
a = [1, 2, 3]
b = [4, 5, 6]
a.extend(b)
print a
print b

a[len(a):] = b
print a
print b

print "index"
knights = ['we', 'are', 'the', 'knights', 'who', 'say', 'ni']
print knights.index('who')
print knights[4]

print "insert"
numbers = [1, 2, 3, 5, 6, 7]
numbers.insert(3, 'four')
print numbers

numbers [3:3] = ['four2']
print numbers

print "pop"
x = [1, 2, 3]
print x.pop()
print x 
print x.pop(0)
print x

print "remove"
y = ['to', 'be', 'or', 'not', 'to', 'be']
y.remove('be')
print y

print "reverse"
z = [1, 2, 3]
z.reverse()
print z

print "sort"
i = [4, 7, 2, 1, 9, 3]
i.sort()
print i

j = i.sort()
print j

i1 = [4, 7, 2, 1, 9, 3]
j1 = i1[:]
j1.sort()
print j1
print i1

i2 = [4, 7, 2, 1, 9, 3]
j2 = i1
j2.sort()
print i2
print j2


i3 = [4, 7, 2, 1, 9, 3]
j3 = sorted(i3)
print i3
print j3

print sorted('pyhont')

print cmp(42, 32)
print cmp(99, 100)
print cmp(10,10)

结果:

append

[1, 2, 3, 4]
count
2
extend
[1, 2, 3, 4, 5, 6]
[4, 5, 6]
[1, 2, 3, 4, 5, 6, 4, 5, 6]
[4, 5, 6]
index
4
who
insert
[1, 2, 3, 'four', 5, 6, 7]
[1, 2, 3, 'four2', 'four', 5, 6, 7]
pop
3
[1, 2]
1
[2]
remove
['to', 'or', 'not', 'to', 'be']
reverse
[3, 2, 1]
sort
[1, 2, 3, 4, 7, 9]
None
[1, 2, 3, 4, 7, 9]
[4, 7, 2, 1, 9, 3]
[4, 7, 2, 1, 9, 3]
[1, 2, 3, 4, 7, 9]
[4, 7, 2, 1, 9, 3]
[1, 2, 3, 4, 7, 9]
['h', 'n', 'o', 'p', 't', 'y']
1
-1
0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值