开发者

What is the difference between {} and [] in python?

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 empty dict
  • columnNames = [] defines an empty list

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 )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜