3 Star 0 Fork 1

mirrors_trekhleb/learn-python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test_identity.py 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
Oleksii Trekhleb 提交于 2018-08-29 23:23 +08:00 . Add Python scripts.
"""Identity operators
@see: https://www.w3schools.com/python/python_operators.asp
Identity operators are used to compare the objects, not if they are equal, but if they are actually
the same object, with the same memory location.
"""
def test_identity_operators():
"""Identity operators"""
# Let's illustrate identity operators based on the following lists.
first_fruits_list = ["apple", "banana"]
second_fruits_list = ["apple", "banana"]
third_fruits_list = first_fruits_list
# is
# Returns true if both variables are the same object.
# Example:
# first_fruits_list and third_fruits_list are the same objects.
assert first_fruits_list is third_fruits_list
# is not
# Returns true if both variables are not the same object.
# Example:
# first_fruits_list and second_fruits_list are not the same objects, even if they have
# the same content
assert first_fruits_list is not second_fruits_list
# To demonstrate the difference between "is" and "==": this comparison returns True because
# first_fruits_list is equal to second_fruits_list.
assert first_fruits_list == second_fruits_list
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_trekhleb/learn-python.git
git@gitee.com:mirrors_trekhleb/learn-python.git
mirrors_trekhleb
learn-python
learn-python
master

搜索帮助