質問編集履歴

3

コードにバグが有ったので追記

2019/04/13 07:13

投稿

cray123
cray123

スコア47

test CHANGED
File without changes
test CHANGED
@@ -18,9 +18,23 @@
18
18
 
19
19
  # このif文をきれいに書きたい
20
20
 
21
+
22
+
23
+ # dic['test']がNoneの場合エラーになる
24
+
21
25
  if 'test' in dic and len(dic['test']) == 0 and dic['test'] is not None :
22
26
 
23
27
  test = dic['test']
28
+
29
+
30
+
31
+ # 追記
32
+
33
+ if 'test' in dic and dic['test'] is not None and len(dic['test']) == 0 :
34
+
35
+ test = dic['test']
36
+
37
+
24
38
 
25
39
  else:
26
40
 

2

追記

2019/04/13 07:13

投稿

cray123
cray123

スコア47

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ```
6
6
 
7
- # 想定してるdicのパターン
7
+ # 以下のパターンを引っ掛けたい
8
8
 
9
9
  dic = {"hello": "hello"}
10
10
 

1

誤字修正

2019/04/13 07:07

投稿

cray123
cray123

スコア47

test CHANGED
File without changes
test CHANGED
@@ -22,6 +22,10 @@
22
22
 
23
23
  test = dic['test']
24
24
 
25
+ else:
26
+
27
+ print("error")
28
+
25
29
 
26
30
 
27
31
  ```