實際上是通過編號對數組進行引用,第四章的字典則是通過名字引用
列表可以修改 元組不能修改
按編號獲取元素
test="hello world"PRint test[0] #獲取第1個元素print test[-1]#獲取倒數第一個元素輸出結果
hdPress any key to continue . . .輸出結果
helello worlello worldel olPress any key to continue . . .輸出結果
[1, 2, 3, 4, 5, 6]helloworldPress any key to continue . . .輸出結果
[1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]hellohellohellohellohelloPress any key to continue . . .輸出結果
TrueFalsePress any key to continue . . .輸出結果
441Press any key to continue . . .輸出結果
['h', 'e', 'l', 'l', 'o']Press any key to continue . . .輸出結果
[1, 4, 3]['a', 'b']['a', 'a', 's', 'd']['a', 'a', 's', 'd', 'a', 's', 'd']['a']Press any key to continue . . .輸出結果
[1, 2, 3, 2]421[1, 2, 3, 4, 5]3[1, 2, 3, 'as', 4, 2, 12, 3, 1, 1, 1]2[1, 2, 3, 4, 2, 12, 3, 1, 1][1, 2, 4, 2, 12, 3, 1, 1, 2][2, 1, 1, 3, 12, 2, 4, 3, 2, 1][1, 1, 1, 2, 2, 2, 3, 3, 4, 12][1, 1, 1, 2, 2, 2, 3, 3, 4, 12]1-1Press any key to continue . . .輸出結果
1 2 3(1, 2, 3)()(2,)10(5, 5)(1, 2, 3)('a', 's')Press any key to continue . . .新聞熱點
疑難解答