1.創建一個henan的空列表,添加zhengzhou,kaifeng,shangqiu,jiaozuo,xinyang元素; 2.在kaifeng元素前面插入一個luoyang元素; 3.把元素xinyang改成中文信陽; 4.在元素jiaozuo後面插入一個子列表[hebi,xuchang]; ...
1.創建一個henan的空列表,添加zhengzhou,kaifeng,shangqiu,jiaozuo,xinyang元素;
henan = []
henan.extend(['zhengzhou','kaifeng','shangqiu','jiaozuo','xinyang'])
print(henan)
['zhengzhou', 'kaifeng', 'shangqiu', 'jiaozuo', 'xinyang']
2.在kaifeng元素前面插入一個luoyang元素;
henan.insert(1,'luoyang')
print(henan)
['zhengzhou', 'luoyang', 'kaifeng', 'shangqiu', 'jiaozuo', 'xinyang']
3.把元素xinyang改成中文信陽;
henan[-1] = '信陽'
print(henan)
['zhengzhou', 'luoyang', 'kaifeng', 'shangqiu', 'jiaozuo', '信陽']
4.在元素jiaozuo後面插入一個子列表[hebi,xuchang];
list = ['hebi','xuchang']
henan.insert(-1,list)
print(henan)
['zhengzhou', 'luoyang', 'kaifeng', 'shangqiu', 'jiaozuo', ['hebi', 'xuchang'], '信陽']
5.列印元素shangqiu的索引值;
print('shangqiu的索引值:',henan.index('shangqiu'))
shangqiu的索引值: 3
6.創建新列表[1,2,3,4,5,6,2],與henan列表合併;
number = [1,2,3,4,5,6,2]
henan.extend(number)
print(henan)
['zhengzhou', 'luoyang', 'kaifeng', 'shangqiu', 'jiaozuo', ['hebi', 'xuchang'], '信陽', 1, 2, 3, 4, 5, 6, 2]