2009-12-14から1日間の記事一覧

文字列の比較で疑問(4)

西尾さんに質問したら丁寧に解説してくれた。Pythonで2つの文字列がa == bだけどもnot(a is b)であるようなケース質問するに当たって確認された事は、対話的環境を使用したかどうか。答えはyes。というわけで試してみた。 対話型インタプリタとの会話 d1 = '…

文字列の比較で疑問(3)

疑問点が変わったけどこのタイトルのままで。 d1 = 'aaa' d2 = 'aaa' id(d1) # => 27605792 id(d2) # => 27605792 ふむ。で、ここから疑問。 d1 = 'a a' d2 = 'a a' id(d1) # => 27605856 id(d2) # => 27606080 えっなんで?

文字列の比較で疑問(2)

d1 = 'string' d2 = d1 'yes' if d1 == d2 else 'no' # => 'yes' 'yes' if d1 is d2 else 'no' # => 'yes' おっ?何かが見えてきたような気がする。[追記]気のせいだった。うーむ。

文字列の比較で疑問(1)

d1 = 'string' d2 = 'string' 'yes' if d1 == d2 else 'no' # => 'yes' 'yes' if d1 is d2 else 'no' # => 'yes' ふむふむ d1 = 'str int' d2 = 'str int' 'yes' if d1 == d2 else 'no' # => 'yes' 'yes' if d1 is d2 else 'no' # => 'no' えっなんで?自分…