可以使用Python内置的“==”运算符来比较两个元组中的内容是否相同。示例如下:
tuple1 = (1, 2, 3, 4, 5) tuple2 = (1, 2, 3, 4, 5) tuple3 = (1, 2, 3, 4, 6)
if tuple1 == tuple2: print("Tuple1 and Tuple2 are identical") else: print("Tuple1 and Tuple2 are not identical")
if tuple1 == tuple3: print("Tuple1 and Tuple3 are identical") else: print("Tuple1 and Tuple3 are not identical")
运行结果为: Tuple1 and Tuple2 are identical Tuple1 and Tuple3 are not identical
上一篇:比较给定时间与当前时间的差异
下一篇:比较给定元组中的内容