Python列表可以包含list和tuple作为元素,因此元组是否可以包含元组作为成员?
>>> lst1 = [1, 3, 5]
>>> lst2 = [2, 4, 6]
>>> tup1 = (9, 7, 5)
>>> tup2 = (8, 6, 4)
>>> clist = [lst1, lst2, tup1, tup2]
>>> print(clist)
[[1, 3, 5], [2, 4, 6], (9, 7, 5), (8, 6, 4)]
答案 0 :(得分:3)
是的,元组可以包含元组作为成员。语法如下:
(1, 2, (3, 4), 5)
或者也许:
tup2 = (3, 4)
tup1 = (1, 2, tup2, 5)