为什么= =(而不仅仅是=) [英] Why = = (and not just =)

查看:93
本文介绍了为什么= =(而不仅仅是=)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉,我无法帮助解决愚蠢的问题:


我明白为什么我们需要= =在C中,但为什么在Python(或Java)中,

当然如果你写了

如果a = b:传递#语法错误

它不可能意味着除了我想要的任何东西

(当然如果a = = b :)?

Sorry, I cant help aking stupid questions:

I understand why we need = = in C, but why in Python (or Java),
surely if you write
if a=b: pass # syntax error
it could not possibly mean anything other than what I intended
(which was of course if a = = b:) ?

推荐答案

Joe Green写道:
Joe Green wrote:
抱歉,我无法帮助愚蠢的问题:

我理解为什么我们需要= =在C中,但为什么在Python(或Java)中,
如果你写的话肯定是
如果a = b:传递#语法错误
它不可能意味着我想要的东西
(当然,如果a = = b :)?
Sorry, I cant help aking stupid questions:

I understand why we need = = in C, but why in Python (or Java),
surely if you write
if a=b: pass # syntax error
it could not possibly mean anything other than what I intended
(which was of course if a = = b:) ?




当然,人们可以使用=。表示相等的测试。

但是,我相信这个语法是从ABC继承而来的,它可能是从B继承的。另外,它*是*有用的

在语法上区分赋值和相等测试

即使解析器不需要这样的区别:人类读者可能会被骗到b $ b什么东西都不存在。


问候,

马丁



Certainly, one could have use "=" to denote the test for equality.
However, I believe that this syntax was inherited from ABC, which
probably inherited it from C. In addition, it *is* useful to
syntactically distinguish between assignments and equality tests
even if the parser does not need that distinction: The human reader
might be tricked into seeing something that isn''t there.

Regards,
Martin


Joe Green写道:
Joe Green wrote:
抱歉,我无法帮助解决愚蠢的问题:

我理解为什么我们需要= =在C中,但为什么在Python(或Java) ),
肯定如果你写了
如果a = b:传递#语法错误
它不可能意味着除了我想要的任何东西
(当然,如果a = = b :)?
Sorry, I cant help aking stupid questions:

I understand why we need = = in C, but why in Python (or Java),
surely if you write
if a=b: pass # syntax error
it could not possibly mean anything other than what I intended
(which was of course if a = = b:) ?




我不是特别喜欢它,但你可以链接作业:



I don''t particularly like it, but you can chain assignments:

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

a = b = = 2
a,b
(真,2)
b = 1
a = b = 2
a,b (2, 2)
a = b == 2
a,b (True, 2)




HTH,

Peter



HTH,
Peter


>>>>> 乔格林 <所以***** @ microsoft.com> (JG)写道:


JG>对不起,我无法帮助解决愚蠢的问题:

JG>我理解为什么我们需要= =在C中,但为什么在Python(或Java)中,

JG>当然,如果你写的是

JG>如果a = b:传递#语法错误

JG>它不可能意味着我想要的任何东西

JG> (当然,如果a = = b :)?


那么a = b = c与a = b == c怎么样?


-

Piet van Oostrum< pi ** @ cs.uu.nl>

网址: http://www.cs.uu.nl/~piet [PGP]

私人电子邮件: P.***********@hccnet.nl
>>>>> "Joe Green" <so*****@microsoft.com> (JG) wrote:

JG> Sorry, I cant help aking stupid questions:
JG> I understand why we need = = in C, but why in Python (or Java),
JG> surely if you write
JG> if a=b: pass # syntax error
JG> it could not possibly mean anything other than what I intended
JG> (which was of course if a = = b:) ?

So what about a = b = c vs. a = b==c?

--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.***********@hccnet.nl


这篇关于为什么= =(而不仅仅是=)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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