詹惠儿

2018-12-07   阅读量: 562

数据分析师 Python数据分析 Python编程

python运算符的==

扫码加入数据分析学习群

运用==的操作者操作数和检查两者的值相等的值进行比较。虽然运营商检查两个操作数是否指向同一对象或没有。

# python3 code to

# illustrate the

# difference between

# == and is operator

# [] is an empty list

list1 = []

list2 = []

list3=list1

if (list1 == list2):

print("True")

else:

print("False")

if (list1 is list2):

print("True")

else:

print("False")

if (list1 is list3):

print("True")

else:

print("False")

  • 第一个if条件的输出为“True”,因为list1和list2都是空列表。
  • 第二条if条件显示“False”,因为两个空列表位于不同的内存位置。因此list1和list2引用不同的对象。我们可以在python中使用id()函数检查它,它返回一个对象的“标识”。
  • 第三个if条件的输出为“True”,因为list1和list3都指向同一个对象。
添加CDA认证专家【维克多阿涛】,微信号:【cdashijiazhuang】,提供数据分析指导及CDA考试秘籍。已助千人通过CDA数字化人才认证。欢迎交流,共同成长!
0.0000 0 5 关注作者 收藏

评论(0)


暂无数据

推荐课程

推荐帖子