pythonでの値の比較とオブジェクトの比較
「==」は値の比較。
「is」はオブジェクトの比較。
>>> foo = 'Boys Be Ambitious' >>> bar = 'Boys Be Ambitious' >>> foo == bar True >>> foo is bar False
短い文字列など、使用頻度の高いオブジェクトは使い回されるので、
「is」での比較は True となる。
>>> foo = 'Boy' >>> bar = 'Boy' >>> foo == bar True >>> foo is bar True