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 1 year has passed since last update.

for _ in range(3) について

Last updated at Posted at 2022-10-21

備忘録

python(3.8.2)のfor文
for _ in range(3)_ について

疑問点

_とは何でしょうか。

調査結果

for _ in range(3)for i in range(3)のように書いてもOKです。
変数名が_になっているだけであり、変数名を_にすることによって、
「その変数を使っていません」ということを表現しています。(Pythonの習慣です)。

ソースコード

N = 3
for i in range(0, N):
    print(i)

for _ in range(0, N):
    print(_)

標準出力

0
1
2
0
1
2
0
0
1

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?