0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Pythonで1から10までの数字の配列のいろいろな作成方法。

Posted at

Pythonで1から10までの数字の配列を作成する方法を書いていきます。
よろしくおねがします。

まず、基本的な配列の方法。

a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

つぎに、for文を使った方法。

a = []
for i in range(1, 11):
  a.append(i)
a = [0]*10
for i in range(10):
  a[i] = i+1

whileを使った方法。

a = []
i = 1
while len(a) < 10:
  a.append(i)
  i += 1
a = [0]*10
i = 0
while not all(a):
  a[i] = i+1
  i += 1

最後に、内包表記の方法。

a = [i for i in range(1, 11)]

以上です。
ありがとうございました。

0
0
2

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?