標籤

python (4) 3Dprinter (1)

2015年7月14日 星期二

Python │ List


# 陣列
array = [#0,#1,#2,.....]
array清單。(#0為第一項,以此類推)

print(array[4][1][3])
表示array清單有三層,左到右依序為外層到最內層,數字表第幾項資料。

# 資料數
print(len(array))
計算出array清單中含有多少資料。

# 附上資料
array.append(X)
在array清單末端附上X資料。

# 取出資料
array.pop(arg
在array清單取出末端的資料(默認),引數可輸入取出資料的位置 。

# 附上多個資料
array.extend(a,b,c) 
在array清單末端附加資料群。

# 移除資料
array.remove(Z)
在array清單中移除特定資料項Z。
array.insert(#position,H)
把一個特定的資料項H加到一個特定的位置。
----------
for迴圈

for target identifier in list :
   list-processing code 
清單中每個資料會依序賦值給目標識別字,每次for迴圈執行時,目標識別字會指向一個不同的資料值,直到用盡清單中的資料值為止。for迴圈只會印出最外層清單的每個項目。
----------
# if...else條件句

if some condition holds :
   the "true" suite 
else :
   the "false" suite 
若條件被滿足時執行the "true" suite,若沒有,執行the "false" suite。
----------
# 檢查型態

isinstance(array,type)
檢查array是否為type型態,是的話print出True,反之False。
----------
# 定義函式

def function name (arg1,arg2,arg3,.......) :
    function code suite 
當發現程式有多個重複的清單套疊,就可以使用def陳述句,引數清單可有可無但括號不可省略。
----------

沒有留言:

張貼留言