is在python中是什么意思_【IT专家】关键字:is和=在python中有什么区别

本文由我司收集整编,推荐下载,如有疑问,请与我司联系

关键字:

is

=

python

中有什么区别

关键字:

is

=

python

中有什么区别

[

]What

is

the

difference

between

keyword: is and == in python the python keyword is is supposed to be used in place of the

== operator according to python style guides.

根据

python

样式指南,

python

关键字应该用于代替

==

运算符。

However they don’t always do exactly the same thing as shown here. Why? What is the

actual difference, and what is the proper usage?

但是,它们并不总是与此处所示完全相同。为什么?实际的差异是什么,正确的

用法是什么?

import

unittestclass

testIS(unittest.TestCase):

def

test_is(self):

self.assertEqual(1,1)if

__name__ == ‘__main__’: unittest.main() Which works... but the following does not...

哪个有效

...

但以下不

...

import

unittestclass

testIS(unittest.TestCase):

def

test_is(self):

self.assertEqual(1,1)if

__name__ is ‘__main__’: unittest.main() 5

is will return True if two variables point to the same object, == if the objects referred to

by the variables are equal.

如果两个变量指向同一个对象,则返回

True;

如果变量引用的对象相等,则返回

=

a = [1, 2, 3] b = a b is a

b == a b = a[:] b is aFalse b == a 7

== tests for equality. Two non-identical objects can be equal.

==

测试平等。两个不相同的对象可以相等。

is tests for identity, i.e. whether both refer to the same one object.

是对身份的测试,即两者是否都指向同一个对象。

2

if

money_in_wallet

is

money_that_was_in_wallet(two_weeks_ago):

print(“I

still

live

with

my

parents

and

have

no

income

or

expenses”)elif

money_in_wallet

==

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值