Python在列表中定义列表

Python在列表中定义列表,python,list,tuples,Python,List,Tuples,我试图定义一个表colors,它包含各种其他表,这些表包含表示颜色的元组 title_label = [ text = (236, 218, 51), background = (125, 142, 246) ], start_button = [ text = (32, 40, 145), background = (236, 235, 136), pressed = (44, 51, 112) ], quit_button = [ text = (166, 21, 13), backgrou

我试图定义一个表colors,它包含各种其他表,这些表包含表示颜色的元组

title_label = [
text = (236, 218, 51),
background = (125, 142, 246)
],
start_button = [
text = (32, 40, 145),
background = (236, 235, 136),
pressed = (44, 51, 112)
],
quit_button = [
text = (166, 21, 13),
background = (48, 61, 188),
pressed = (31, 40, 129)
]

但是,这会产生无效的语法错误。为什么会这样?

列表不采用名称-值对。您可能希望在此处使用字典:

definitions = {
    'title_label': {
        'text': (236, 218, 51),
        'background': (125, 142, 246)
    },
    'start_button': {
        'text': (32, 40, 145),
        'background': (236, 235, 136),
        'pressed': (44, 51, 112)
    },
    'quit_button': {
        'text': (166, 21, 13),
        'background': (48, 61, 188),
        'pressed': (31, 40, 129)
    }
}
我不确定您在哪里找到了语法,但它不是有效的Python。使用[…]方括号的Python列表只能获取单个Python表达式的序列:

some_list = ['one object', {'dictionary': 'value'}, ['another', 'list']]

请参阅Python教程的第页。

您能给出一个关于您想做什么的说明吗?列表不能有这样的标签。您是否阅读了本书以熟悉基本的Python数据结构?