gpt4 book ai didi

python - is 运算符和 == 运算符

转载 作者:太空宇宙 更新时间:2023-11-03 15:30:26 24 4
gpt4 key购买 nike

<分区>

num1num2 都是 3.5,num1 == num2 给出 True,但对于 is 运算符是 False

看下面的代码,

输入:

num1 = 3.5
num2 = float(input('num2:')) # num2 stands for 2nd number
print(num1 == num2)
print(num1 is num2)

输出:

num2:3.5
True
False

num1 and num2 both are 3.5 and num1 == num2 gives True, but for is operator it is False.

为什么是 id(num1) != id(num2)

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com