回答編集履歴

3

修正

2019/01/26 15:55

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -14,9 +14,9 @@
14
14
 
15
15
  ```Python
16
16
 
17
- for i, _ in enumerate(lst):
17
+ for i, e in enumerate(lst):
18
18
 
19
- lst[i] = f'{lst[i]}you' # str(lst[i]) + 'you' でも可
19
+ lst[i] = f'{e}you' # str(e) + 'you' でも可
20
20
 
21
21
  ```
22
22
 

2

追記

2019/01/26 15:55

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -52,6 +52,16 @@
52
52
 
53
53
 
54
54
 
55
+ 文字列に変数の値を埋め込む有効な方法はバージョンに依って異なります。
56
+
57
+ - f-string (Python3.6以降)
58
+
59
+ - str.format
60
+
61
+ - %記法
62
+
63
+
64
+
55
65
  なお
56
66
 
57
67
  ---

1

追記

2019/01/26 15:54

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  for i in range(len(lst)):
6
6
 
7
- lst[i] += 'you'
7
+ lst[i] = f'{lst[i]}you' # str(lst[i]) + 'you' でも可
8
8
 
9
9
  ```
10
10
 
@@ -16,7 +16,7 @@
16
16
 
17
17
  for i, _ in enumerate(lst):
18
18
 
19
- lst[i] += 'you'
19
+ lst[i] = f'{lst[i]}you' # str(lst[i]) + 'you' でも可
20
20
 
21
21
  ```
22
22
 
@@ -32,7 +32,7 @@
32
32
 
33
33
  for e in lst:
34
34
 
35
- dst.append(e + 'you')
35
+ dst.append(f'{e}you') # str(e) + 'you' でも可
36
36
 
37
37
  ```
38
38
 
@@ -44,8 +44,44 @@
44
44
 
45
45
  lst = [
46
46
 
47
- e + 'you' for e in lst
47
+ '{}you'.format(e) for e in lst # str(e) + 'you' でも可
48
48
 
49
49
  ]
50
50
 
51
51
  ```
52
+
53
+
54
+
55
+ なお
56
+
57
+ ---
58
+
59
+ 変数に `list` と命名するのは厳に避けてください。
60
+
61
+ 分かりづらいエラーを引き起こします。
62
+
63
+ ```Python
64
+
65
+ >>> list('spam')
66
+
67
+ ['s', 'p', 'a', 'm']
68
+
69
+ >>>
70
+
71
+ >>> list = []
72
+
73
+ >>>
74
+
75
+ >>> list('spam')
76
+
77
+ Traceback (most recent call last):
78
+
79
+ File "<stdin>", line 1, in <module>
80
+
81
+ TypeError: 'list' object is not callable
82
+
83
+ ```
84
+
85
+
86
+
87
+ 同様につけてしまいがちな名前としては、`max` `id` `len` `str` などがあります。