2011-08-04 35 views
-1

[]是什麼意思? 另外我怎樣才能確定變量爲python中的空數組? 謝謝!Python數組問題(編程)

perl: xcoords =() 

我該如何翻譯?

+0

這不是Perl的。 perl版本是:@xcoords =(); –

+0

對不起,我忘了添加數組符號,我該如何翻譯那個 – enginefree

+0

你是指'[]'還是'()'?在Perl中,他們在那裏做了非常不同的事情。請複製並粘貼你想知道的實際代碼,否則你的問題變得毫無意義。 – ysth

回答

3

[] - 是Python中的一個空列表,與調用list()例如[] ==列表() 要檢查該列表是空的則可以使用LEN(升)或:

listV = [] # an empty list 
if listV: 
    # do something if list is not empty 
else: 
    # do something if list is really empty 

要詳細瞭解列表可以使用the following link

+2

所有空容器的計算結果都爲'False' – tauran

+1

@tbilisidavid,或者您可以使用len(emptyList)來確定列表是否爲空,以防萬一只是想檢查。 – OnesimusUnbound

0

列表是類似於C++的一些陣列區別。不同之處在於它們可以列出不同的類型甚至列表。檢查列表是空的

lists = [] 
len(lists) 
lists[0]= "More of me" 
len(lists) 

更多檢查Python official教程及以上的文檔