LoginSignup
0
2

More than 5 years have passed since last update.

Python > None / True / False > if src is None: / Syntax: a is b / Function: is_(a, b) > is: オブジェクトが同一か / id(a) / ==: 同値かどうか / Flyweightパターン / 数値 比較には==を使う

Last updated at Posted at 2017-03-27

@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic
(No. 2484 / 12833)

To distinguish None from a boolean False value, use Python's is operator:

実装してみた。

def is_none(src):
    if src is None:
        print('None')
    elif src:
        print('True')
    else:
        print('False')

is_none(None)
is_none(0)
is_none([])
is_none({})
is_none(True)
print
is_none(1)
is_none([3.14, 2.718])
is_none({'pi', 3.14})
結果
Success time: 0.01 memory: 23304 signal:0
None
False
False
False
True

True
True
True

http://monmon.hateblo.jp/entry/20110214/1297710749
上記のリンクに記載の以下も参考になる。
http://jaredgrubb.blogspot.jp/2009/04/python-is-none-vs-none.html

operator.is_(a, b)
Return a is b. Tests object identity.

https://docs.python.org/3.6/library/operator.html#mapping-operators-to-functions
Syntaxがa is bで、Functionがis_(a, b)



@shiracamus さんのコメントにて以下の事項を教えていただきました。
情報感謝です。
0
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2