“Inisialisasi daftar boolean ukuran ular piton” Kode Jawaban

Inisialisasi daftar boolean ukuran ular piton

You can do it like this: -

>>> [False] * 10
[False, False, False, False, False, False, False, False, False, False]
NOTE: - Note that, you should never do this with a list of mutable types with same value, else you will see surprising behaviour like the one in below example: -

>>> my_list = [[10]] * 3
>>> my_list
[[10], [10], [10]]
>>> my_list[0][0] = 5
>>> my_list
[[5], [5], [5]]
As you can see, changes you made in one inner list, is reflected in all of them.
Kelsier

Inisialisasi daftar boolean ukuran ular piton

>>> [False] * 10
[False, False, False, False, False, False, False, False, False, False]
Kelsier

Jawaban yang mirip dengan “Inisialisasi daftar boolean ukuran ular piton”

Pertanyaan yang mirip dengan “Inisialisasi daftar boolean ukuran ular piton”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya