【Python爬虫類】-8.13練習問題
2701 ワード
一、
1).
result:
2).
result:
3).
result:
4).
result:
5).
result:
二、
三、
1).
result:
2).
result:
3).
result:
4).
result:
list1 = ['life', 'is' ,'short']
list2 = ['you', 'need', 'python']
1).
print('index:', list2.index('python'), ',', list2[list2.index('python')])
result:
index: 2 , python
2).
list2.append('!')
list1.insert(list1.index('short')+1, ',')
print(list1)
print(list2)
result:
['life', 'is', 'short', ',']
['you', 'need', 'python', '!']
3).
list3 = ['life', 'is' ,'short']
list3.insert(list3.index('short')+1, ',')
list3.extend(list2)
list3.sort()
print(list3, ' length:', len(list3))
result:
['!', ',', 'is', 'life', 'need', 'python', 'short', 'you'] length: 8
4).
list2[list2.index('python')] = 'python3'
print(list2)
result:
['you', 'need', 'python3', '!']
5).
list1.remove(',')
list2.remove('!')
print(list1)
print(list2)
result:
['life', 'is', 'short']
['you', 'need', 'python3']
二、
aTuple = (1,2,3,4,5)
print(aTuple[3])
print(len(aTuple))
4
5
三、
list1 = ['life', 'is', 'short']
list2 = ['you', 'need', 'python']
list3 = [1,2,3,4,5,3,4,2,1,5,7,9]
1).
list_set1 = set(list1)
print(list_set1)
result:
{'short', 'is', 'life'}
2).
list1.extend(list2)
list_set2 = set(list1)
print(list_set2, ' length:', len(list_set2))
result:
{'short', 'life', 'you', 'python', 'is', 'need'} length: 6
3).
list_set1.update(list_set2)
list_set1.remove('python')
print(list_set1)
result:
{'short', 'life', 'you', 'is', 'need'}
4).
list_set1.add('python3')
print(list_set1)
result:
{'short', 'python3', 'life', 'you', 'is', 'need'}