可以使用 Python 中的 len() 函数来计算列表中的项目数量,然后将这些数字进行比较。
示例代码:
list1 = [1, 2, 3, 4, 5]
list2 = [6, 7, 8, 9, 10]
if len(list1) > len(list2):
print("List 1 has more items.")
elif len(list1) < len(list2):
print("List 2 has more items.")
else:
print("Both lists have the same number of items.")
输出结果为:
List 2 has more items.