string と int の 2 つの変数を異なるデータ型で比較したいとします。Python 2.7.3 と Python 3.2.3 の両方でテストしましたが、どちらも例外をスローしません。比較結果は ですFalse
。この場合、例外をスローするさまざまなオプションを使用して Python を構成または実行できますか?
ks@ks-P35-DS3P:~$ python2
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a="123"
>>> b=123
>>> a==b
False
>>>
ks@ks-P35-DS3P:~$ python3
Python 3.2.3 (default, Apr 12 2012, 19:08:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a="123"
>>> b=123
>>> a==b
False
>>>
ks@ks-P35-DS3P:~$