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

前端 未结 7 614
轮回少年
轮回少年 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:19

    Arrays (called list in python) use the [] notation. {} is for dict (also called hash tables, associated arrays, etc in other languages) so you won't have 'append' for a dict.

    If you actually want an array (list), use:

    array = []
    array.append(valueToBeInserted)
    

提交回复
热议问题