“2D array python menginisialisasi” Kode Jawaban

Python menginisialisasi array 2D

x = [[foo for i in range(10)] for j in range(10)]
# x is now a 10x10 array of 'foo' (which can depend on i and j if you want)
Unusual Unicorn

inisialisasi python array 2d

x = [[foo for i in range(10)] for j in range(10)]
# x is now a 10x10 array of 'foo' (which can depend on i and j if you want)
Muddy Magpie

2D array python menginisialisasi

>>> b = [['a']*3]*3
>>> b
[['a', 'a', 'a'], ['a', 'a', 'a'], ['a', 'a', 'a']]
>>> b[1][1]
'a'
>>> b[1][1] = 'b'
>>> b
[['a', 'b', 'a'], ['a', 'b', 'a'], ['a', 'b', 'a']]
Grumpy Gaur

2D array python menginisialisasi


bar = []
for item in some_iterable:
    bar.append(SOME EXPRESSION)

Amused Addax

Jawaban yang mirip dengan “2D array python menginisialisasi”

Pertanyaan yang mirip dengan “2D array python menginisialisasi”

Lebih banyak jawaban terkait untuk “2D array python menginisialisasi” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya