检查两个元组列表在 Python 中是否相同
当需要检查两个元组列表是否相同时,请使用 '==' 运算符。
'==' 运算符检查两个迭代对象是否相等。
列表可用于存储异构值(即任何数据类型的数据,如整数、浮点数、字符串等)。
元组的列表基本上包含封装在列表中的元组。
以下是相同的示例 −
示例
my_list_1 = [(11, 14), (54, 58)]
my_list_2 = [(98, 0), (10, 13)]
print("The first list of tuple is : ")
print(my_list_1)
print("The second list of tuple is : ")
print(my_list_2)
my_result = my_list_1 == my_list_2
print("Are the list of tuples identical?")
print(my_result)输出
The first list of tuple is : [(11, 14), (54, 58)] The second list of tuple is : [(98, 0), (10, 13)] Are the list of tuples identical? False
说明
- 定义了两个元组列表,并在控制台上显示。
- 使用 '==' 运算符检查元组是否相同。
- 将其分配给一个值。
- 它显示在控制台上。
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP