Code
#1定义列表
list1=['life','is','short']
list2=['you','need','python']
#1)
index=list2.index('python')
print(list2[2])
print(index)
#2)
list1.append(',')
list2.append('!')
print(list1)
print(list2)
#3
list1.extend(list2)
print(len(list1))
#4
list2.remove('python')
list2.insert(2,'python3')
print(list2 )
#5
list1.remove(',')
list1.remove('!')
print(list1)
#2自定义
tuple=(1,2,'3',4,'Fun',True,'False')
print(type(tuple))
print(len(tuple))
print(tuple[4])
#3列表
list_set1=['life','is','short']
list_set2=['you','need','python']
list_set3=[1,2,3,4,5,3,4,2,1,5,7,9]
#1
list_set1=set(list_set1)
print(list_set1)
print(type(list_set1))
#2
list_set2=set(list_set2)
list_set2.update(list_set1)
print(list_set2)
#3
print(len(list_set2))
print(len(list_set1))
#4
list_set2.remove('python')
print(list_set2)
#5
list_set2.add('python3')
print(list_set2)
Output:
python2['life', 'is', 'short', ',']
['you', 'need', 'python', '!']
8
['you', 'need', 'python3', '!']
['life', 'is', 'short', 'you', 'need', 'python']
7
Fun
{'life', 'is', 'short'}
{'life', 'is', 'you', 'short', 'python', 'need'}
6
3
{'life', 'is', 'you', 'short', 'need'}
{'life', 'is', 'you', 'short', 'python3', 'need'}
网友评论