python 中的 == 和 is 运算符之间的差异。
is 和 equals(==) 运算符在很多情况下表现相同,但实际上它们并不相同。is 运算符用于判断两个变量是否指向同一对象,而 == 运算符用于检查两个变量的值是否相同。
示例代码
# Python program 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")
输出
True False True
数据结构
网络
关系型数据库管理系统
操作系统
java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP