2014/01/22

Python 3.3 List

#List
m_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 
 
for index in m_list:
 print (index, end=', ')
 
print()
 
#印出第三個元素
print(m_list[2], "\n")
 
#印出倒數第三個元素
print(m_list[-3], "\n")
 
#印出全部,但不新增到List
for index in m_list + [11, 12, 13, 14, 15]:
 print (index, end=', ')
print()
 
for index in m_list:
 print (index, end=', ')
print()
 
#將第一個元素改成 3^3
m_list[0] = 3**3
print (m_list[0])
 
#將11加入到List
m_list.append(11)
for index in m_list:
 print (index, end=', ')
print()
 
#將List加入List
m_list.append([12, 13, 14, 15])
for index in m_list:
 print (index, end=', ')
print()





參考資料:
http://docs.python.org/3/tutorial/introduction.html#lists
http://docs.python.org/3/glossary.html#term-sequence