檢查兩個元組列表在 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
說明
- 定義了兩個元組列表,並在控制檯上顯示。
- 使用 '==' 運算子檢查元組是否相同。
- 將其分配給一個值。
- 它顯示在控制檯上。
廣告