How to declare and add items to an array in Python?

前端 未结 7 555
轮回少年
轮回少年 2020-11-28 01:46

I\'m trying to add items to an array in python.

I run

array = {}

Then, I try to add something to this array by doing:



        
相关标签:
7条回答
  • 2020-11-28 02:25

    No, if you do:

    array = {}
    

    IN your example you are using array as a dictionary, not an array. If you need an array, in Python you use lists:

    array = []
    

    Then, to add items you do:

    array.append('a')
    
    0 讨论(0)
提交回复
热议问题