python3-列表

2020-01-03 16:13:50 浏览数 (1)

del如下。pop弹出元素并返回。

代码语言:javascript复制
print(x)
[1, 2, 5, 6, 8, 4, 3, 5]

del x[3]
print(x)
[1, 2, 5, 8, 4, 3, 5]

y=x.pop()
print(y)
5

x
print(x)
[1, 2, 5, 8, 4, 3]
代码语言:javascript复制
print(x)
[1, 2, 5, 8, 4, 3]

x
z=x.pop(3)
print(x)
[1, 2, 5, 4, 3]

z
print(z)
8
代码语言:javascript复制
x1=(1,2,"aaaa")
x2=(3,4,"bbbb")

x1,x2
print(x1,x2)
(1, 2, 'aaaa') (3, 4, 'bbbb')
x1
(1, 2, 'aaaa')

x2
x2
(3, 4, 'bbbb')

print(x1[0],x1[1])
1 2

print(x2[2],x1[1])
bbbb 2

print(x)
x3=tuple(x)
print(x3)
[1, 2, 5, 4, 3, 10, 20, [1, 2]]
(1, 2, 5, 4, 3, 10, 20, [1, 2])

print(x3[5],x3[6])
10 20

1
print(x[7][0])
print(x[7][1])
1
2

0 人点赞