LoginSignup
0
0

More than 5 years have passed since last update.

配列をforで初期化

Posted at

配列をfor文を使って初期化する方法

こんな感じで作成できる。

list1 = [i for i in range(5)]
print(list1)

list2 = [str(i + 1) for i in range(5)]
print(list2)

<出力結果>
[0, 1, 2, 3, 4]
['1', '2', '3', '4', '5']

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0