What is开发者_运维问答 the difference between columnNames = {} and columnNames = [] in python?
How can i iterate each one? using {% for value in columnNames %} OR for idx_o, val_o in enumerate(columnNames):
columnNames = {}defines an emptydictcolumnNames = []defines an emptylist
These are fundamentally different types. A dict is an associative array, a list is a standard array with integral indices.
I recommend you consult your reference material to become more familiar with these two very important Python container types.
In addition to David's answer here is how you usually iterate them:
# iterating over the items of a list
for item in someList:
print( item )
# iterating over the keys of a dict
for key in someDict:
print( key, someDict[key] )
# iterating over the key/value pairs of a dict
for ( key, value ) in someDict.items():
print( key, value )
加载中,请稍侯......
精彩评论