質問のif文のテストを実際にやってみました。(^_^;
Pythonの場合、「NULL」は「None」になります。
● TestIf.py
# coding: UTF-8 # TestIf.py print(u'①x = -1') if -1: print('TRUE') else: print('FALSE') print(u'②x = 0') if 0: print('TRUE') else: print('FALSE') print(u'③x = 1') if 1: print('TRUE') else: print('FALSE') print(u'④x = 5') if 5: print('TRUE') else: print('FALSE') print(u'⑤x = ""') if "": print('TRUE') else: print('FALSE') print(u'⑥x = "hello"') if "hello": print('TRUE') else: print('FALSE') print(u'⑦x = NULL') if None: print('TRUE') else: print('FALSE')
●実行結果
①x = -1 TRUE ②x = 0 FALSE ③x = 1 TRUE ④x = 5 TRUE ⑤x = "" FALSE ⑥x = "hello" TRUE ⑦x = NULL FALSE
※参考URL
http://d.hatena.ne.jp/nekora/20100105/p2
Javascriptの場合、「NULL」は「null」になります。
● TestIf.html
<html> <head> <title>TestIf.html</title> </head> <body> <script type='text/javascript'> document.write('①x = -1<br>'); if(-1) document.write('TRUE<br>') else document.write('FALSE<br>') document.write('②x = 0<br>'); if(0) document.write('TRUE<br>') else document.write('FALSE<br>') document.write('③x = 1<br>'); if(1) document.write('TRUE<br>') else document.write('FALSE<br>') document.write('④x = 5<br>'); if(5) document.write('TRUE<br>') else document.write('FALSE<br>') document.write('⑤x = ""<br>'); if("") document.write('TRUE<br>') else document.write('FALSE<br>') document.write('⑥x = "hello"<br>'); if("hello") document.write('TRUE<br>') else document.write('FALSE<br>') document.write('⑦x = NULL<br>'); if(null) document.write('TRUE<br>') else document.write('FALSE<br>') </script> </body> </html>
●実行結果
①x = -1 TRUE ②x = 0 FALSE ③x = 1 TRUE ④x = 5 TRUE ⑤x = "" FALSE ⑥x = "hello" TRUE ⑦x = NULL FALSE
質問のコメントのURLのまとめが良かったのではっておきます。 o(^-^)o
※参考URL
http://blog.mirakui.com/entry/20090604/truefalse
VBAもやってみました。⑤と⑥で「型が一致しません。」とエラーが出てストップしてしまうので、「On Error Resume Next」を使ってみました。(^_^;
● TestIf.xlsx
Public Sub TestIf() On Error Resume Next Debug.Print "①x = -1" If -1 Then Debug.Print "TRUE" Else Debug.Print "FALSE" End If Debug.Print "②x = 0" If 0 Then Debug.Print "TRUE" Else Debug.Print "FALSE" End If Debug.Print "③x = 1" If 1 Then Debug.Print "TRUE" Else Debug.Print "FALSE" End If Debug.Print "④x = 5" If 5 Then Debug.Print "TRUE" Else Debug.Print "FALSE" End If Debug.Print "⑤x = " + Chr(34) + Chr(34) If "" Then Debug.Print "TRUE" Else Debug.Print "FALSE" End If If Err.Number <> 0 Then Debug.Print Err.Number Debug.Print Err.Description End If Debug.Print "⑥x = " + Chr(34) + "hello" + Chr(34) If "hello" Then Debug.Print "TRUE" Else Debug.Print "FALSE" End If If Err.Number <> 0 Then Debug.Print Err.Number Debug.Print Err.Description End If Debug.Print "⑦x = NULL" If Null Then Debug.Print "TRUE" Else Debug.Print "FALSE" End If End Sub
●実行結果
①x = -1 TRUE ②x = 0 FALSE ③x = 1 TRUE ④x = 5 TRUE ⑤x = "" TRUE 13 型が一致しません。 ⑥x = "hello" TRUE 13 型が一致しません。 ⑦x = NULL FALSE