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