回答編集履歴
1
追記
answer
CHANGED
@@ -1,1 +1,21 @@
|
|
1
|
+
リストの中の要素を順番に取り出す方法です。```for item in line:...```という表記が使えます。
|
2
|
+
|
3
|
+
```Python
|
4
|
+
line = "1 2 3 4" # input()
|
5
|
+
line = line.split()
|
6
|
+
for item in line:
|
7
|
+
print(int(item) + 1)
|
8
|
+
# 2
|
9
|
+
# 3
|
10
|
+
# 4
|
11
|
+
# 5
|
12
|
+
```
|
13
|
+
|
14
|
+
もしくは、```range(n)```を使って次のようにも書けます。
|
15
|
+
```Python
|
16
|
+
line = "1 2 3 4" # input()
|
17
|
+
line = line.split()
|
1
|
-
len(line)
|
18
|
+
n = len(line)
|
19
|
+
for i in range(n):
|
20
|
+
print(int(line[i]) + 1)
|
21
|
+
```
|