#!/usr/bin/python3
list1 = ['Google', 'Runoob', 'Taobao', 'Baidu'];
list2 = [1, 1, 2, 3] + [ 4, 5, 6, 7 ];
list3 = ['hi'] * 5
print("list1:", list1)
print("list2:", list2)
print("list3:", list3)
# 访问方式:索引 和 切片(前闭后开)
print ("list1[0]: ", list1[0])
print ("list2[1:5]: ", list2[1:5])
# 更新:
list2[3] = 2001
print("list2更新第三个元素: ", list2)
del list1[3]
print ("list1删除第三个元素 : ", list1)
if 1 in list2:
print("yes : 1 in list2 ")
for x in list1:
print(x, end = ' ')
print(max(list2))
list2.append(8)
print(list2)
print(list2.count(1))
list1.reverse()
print(list1)
print(list2.pop(4))
打印结果:
list1: ['Google', 'Runoob', 'Taobao', 'Baidu'] list2: [1, 1, 2, 3, 4, 5, 6, 7] list3: ['hi', 'hi', 'hi', 'hi', 'hi'] list1[0]: Google list2[1:5]: [1, 2, 3, 4] list2更新第三个元素: [1, 1, 2, 2001, 4, 5, 6, 7] list1删除第三个元素 : ['Google', 'Runoob', 'Taobao'] yes : 1 in list2 Google Runoob Taobao 2001 [1, 1, 2, 2001, 4, 5, 6, 7, 8] 2 ['Taobao', 'Runoob', 'Google'] 4