输入语句 >>> list1=[1,2,3] >>> list1 >>> list2=list("AB01") >>> list2 >>> list1[0] >>> list2[1] >>> list2[-1] >>> list2[-4] >>> list1[1]=list1[-1]+list1[1] >>> list1 >>> list1[3] >>> del list2[0] >>> list2 >>> del list2 >>> list2 >>> list3=[6,7] >>> list4=list1+list3 >>> list4 >>> list1+=list3 >>> list1 >>> list2=list3*2 >>> list2 >>> 1 in list1 >>> 1 in list2 >>> list2>list1 >>> len(list1) >>> max(list1) >>> min(list1) >>> sum(list1) >>> list5=sorted(list1) >>> list5 >>> list6=list(reversed(list1)) >>> list6 >>> list1 >>> list1.append(2) >>> list1 >>> list1.insert(2,8) >>> list1 >>> list1.pop() >>> list1 >>> list1.pop(2) >>> list1 >>> list1.remove(6) >>> list1 >>> list1.index(3) >>> list1.clear() >>> list1 >>> list1.extend([1,2,2,4,2,3]) >>> list1 >>> list1.count(2) >>> list1.reverse() >>> list1 >>> list1.sort() >>> list1 >>> list2=list1 >>> list2.append(5) >>> list1 >>> list3=list1.copy() >>> list3.remove(2) >>> list3 >>> list1 >>> lb=[i for i in range(7)] >>> lb >>> lb[1:5] >>> lb[1::2] >>> lb[-2::-2] >>> lb[::-1] >>> lb[len(lb):]=[7] >>> lb >>> lb[1:1]=[8,9] >>> lb >>> lb[3:5]=[10,11] >>> lb >>> lb[5:]=[] >>> lb >>> del lb[::2] >>> lb输出及说明
时间: 2023-11-23 19:54:17 浏览: 134
输入法练习
输出结果如下:
[1, 2, 3]
['A', 'B', '0', '1']
1
'B'
'1'
IndexError: list index out of range
[1, 6, 3]
IndexError: list index out of range
['B', '0', '1']
[]
[1, 2, 3, 6, 7]
[1, 2, 3, 6, 7]
[6, 7, 6, 7]
False
True
False
5
7
1
19
[1, 2, 2, 2, 3, 4]
[4, 2, 2, 2, 3, 1]
[1, 2, 2, 2, 3, 4, 2]
[1, 2, 2, 2, 3, 4, 6, 7]
[1, 2, 2, 2, 3, 4, 6, 7]
[2, 2, 3, 4, 1, 2, 2, 2, 3, 4]
[1, 2, 2, 2, 2, 2, 3, 3, 4]
[1, 2, 2, 2, 2, 2, 3, 3, 4, 2, 5]
[1, 2, 2, 2, 2, 2, 3, 3, 4, 2, 5]
[1, 8, 9, 2, 2, 2, 2, 2, 3, 3, 4, 2, 5]
[1, 8, 9, 2, 10, 11, 2, 2, 3, 3, 4, 2, 5]
[1, 8, 9, 2, 10, 2, 5]
[8, 2, 2, 4, 2, 3]
[5, 2, 2, 4, 2, 3]
[1, 2, 2, 4, 2, 3]
[1, 2, 2, 4, 2, 3, 2]
[1, 2, 2, 8, 9, 4, 2, 3, 2]
[1, 2, 10, 11, 8, 9, 4, 2, 3, 2]
[10, 8, 4, 3, 2]
说明:
以上是对Python中列表的一些常见操作进行演示和说明。其中包括了列表的基本操作,如索引、切片、增删改查等;列表的常用方法,如append、extend、insert、pop、remove、index、sort等;以及对列表进行复制、拷贝、排序、反转等操作。此外,还演示了列表推导式和一些高级切片操作。
阅读全文