medical_list = ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot']
type(medical_list)
list
list('123')
['1', '2', '3']
list(123)
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-3-1c325c17b3d1> in <module> ----> 1 list(123) TypeError: 'int' object is not iterable
print('Length of list\t:', len(medical_list))
print('[0]\t\t:', medical_list[0])
print('[1:5:3]\t\t:', medical_list[1:5:3])
Length of list : 6 [0] : toothache [1:5:3] : ['pimple', 'asthma']
medical_list = ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot']
medical_list.append('headache')
medical_list.append('nausea')
medical_list.append('vomitting')
medical_list
['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomitting']
medical_list = ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot']
recent_illness = ['headache', 'nausea', 'vomitting']
medical_list.extend(recent_illness)
medical_list
['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomitting']
medical_list = ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot']
recent_illness = ['headache', 'nausea', 'vomitting']
medical_list = medical_list + recent_illness
medical_list
['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomitting']
medical_list = ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot']
recent_illness = ['headache', 'nausea', 'vomitting']
medical_list += recent_illness # 我改了這行
medical_list
['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomitting']
底數 = 2
對數 = 10
底數 **= 對數
底數 # 已經不是底數的底數
1024
medical_list = ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomitting']
print('vomitting 的位置:', medical_list.index('vomitting'))
medical_list[(medical_list.index('vomitting'))] = 'vomiting'
print('拼字正確的清單', medical_list)
vomitting 的位置: 8 拼字正確的清單 ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomiting']
medical_list = ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomiting']
print('2. 給你看', medical_list.pop())
print('1. 拿出來', medical_list)
2. 給你看 vomiting 1. 拿出來 ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea']
medical_list = ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomiting']
print('pimple的位置', medical_list.index('pimple'))
print('拿出來給你看', medical_list.pop(medical_list.index('pimple')))
print(medical_list)
pimple的位置 1 拿出來給你看 pimple ['toothache', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomiting']
medical_tuple = ('toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomitting')
type(medical_tuple)
tuple
medical_list = ['toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomitting']
medical_tuple = tuple(medical_list)
medical_tuple
('toothache', 'pimple', 'myopia', 'astigmatism', 'asthma', 'flatfloot', 'headache', 'nausea', 'vomitting')
medical_tuple[-1]
'vomitting'
medical_tuple[-1] = 'vomiting'
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-16-76f9e11e8084> in <module> ----> 1 medical_tuple[-1] = 'vomiting' TypeError: 'tuple' object does not support item assignment