Python之List與Tuple型別
1. Python建立list
L = ['Adam', 95.5, 'Lisa', 85, 'Bart', 59]
print L
2. Python依照索引存取list
L = [95.5,85,59]
print L[0]
print L[1]
print L[2]
print L[3]
3. Pythonrrrrrlllist
5. Python從list刪除元素
L = [95.5, 85, 59]
print L[-1]
print L[-2]
print L[-3]
print L[-4]
6. Python中替換元素
L = ['Adam', 'Lisa', 'Bart']
L.insert(2, 'Paul')
print L
7. Python建立tuple
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(3)
L.pop(2)
print L
8. Python之創建單元素tuple
L = ['Adam', 'Lisa', 'Bart']
L[0] = 'Bart'
L[-1] = 'Adam'
print L
9. Python之「可變」的tuple
t = (0,1, 2, 3, 4, 5, 6, 7, 8, 9)
print t
更多Python之List和Tuple類型 相關文章請關注PHP中文網!