“a是b”的结果 [英] Result of ``a is b''

查看:107
本文介绍了“a是b”的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


有以下行为的理由:

a =(1,2)
b =(1,2)
a是b
假a =12
b =" 12"
a是b



True


谢谢,

Axel

解决方案

" Axel Boldt" <斧******* @ yahoo.com>在消息中写道

news:40 ************************** @ posting.google.c om ...

是否存在以下行为的基本原理:

>>> a =(1,2)
>>> b =(1,2)
>>> a是b False>>> a =12
>>> b =" 12"
>>> a是b True




可能是实施意外。考虑:

a =" 1 2"
b =" 1" + 2
a是b
False


,就此而言:

a =(1,2)
b = a
a是b



正确


你有什么理由关心关于这种行为?


Axel Boldt写道:

是否存在以下行为的理由:




是的:对你来说实施工作并不重要。


-

__ Erik Max Francis&& ma*@alcyone.com && http://www.alcyone.com/max/

/ \美国加利福尼亚州圣何塞市&& 37 20 N 121 53 W&& & tSftDotIotE

\ __ /我唯一遗憾的是,我的国家只有一次失败。

- Nathan Hale


> >>> a =(1,2)

>>> b =(1,2)
>>> a是b False>>> a =12
>>> b =" 12"
>>> a是b True




除非你关心两个名字是否指向同一个对象,否则不要使用

''是'' 。而是将'==''与等式进行比较。这应该像

你想要的那样:

a =(1,2)
b =(1,2)
a == b
True a =" 12"
b =" 12"
a == b



真的


它还将处理Andrew指出的案例。


- Josiah


Hello,

is there a rationale for the following behavior:

a = (1,2)
b = (1,2)
a is b False a = "12"
b = "12"
a is b


True

Thanks,
Axel

解决方案

"Axel Boldt" <ax*******@yahoo.com> wrote in message
news:40**************************@posting.google.c om...

is there a rationale for the following behavior:

>>> a = (1,2)
>>> b = (1,2)
>>> a is b False >>> a = "12"
>>> b = "12"
>>> a is b True



Probably an accident of implementation. Consider:

a = "1 2"
b = "1" + " 2"
a is b False

and, for that matter:
a = (1, 2)
b = a
a is b


True

Is there a reason that you care about this behavior?


Axel Boldt wrote:

is there a rationale for the following behavior:



Yes: It shouldn''t matter to you what the implementation is doing.

--
__ Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ I only regret that I have but one life to lose for my country.
-- Nathan Hale


> >>> a = (1,2)

>>> b = (1,2)
>>> a is b False >>> a = "12"
>>> b = "12"
>>> a is b True



Unless you care whether two names point to the same object, don''t use
''is''. Instead compare for equality with ''==''. That should work like
you want it to:

a = (1,2)
b = (1,2)
a == b True a = "12"
b = "12"
a == b


True

It will also handle the cases that Andrew points out.

- Josiah


这篇关于“a是b”的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆