关于Python:Python – 列表中冒号的语法错误

Python - Syntax error on colon in list

我一直在尝试创建一个简单的字典来定义用户输入的单词。在定义了字典和单词之后,我试图打印输入单词的定义。出于某种原因,当我尝试运行这个程序时,列表中的冒号有语法错误。我不知道如何解决这个问题,我知道有更简单的方法可以解决这个问题,但我正在尝试练习使用列表。以下是迄今为止的代码:

词典

1
2
3
4
5
6
7
8
9
10
11
12
dic1 = [
    'bug':'A broken piece of code that causes a program to stop functioning'
    'string':'A piece of text'
    'integer':'A whole number'
    'float':'A decimal number'
    'function':'A block of organized and clean code that performs a task/action'
    'syntax':'A set of rules that says how a program will be coded'      
    ]

q = input("What coding related word do you want defined?")
if q in dic1:
    print(dic1[q])

你忘了在听写的每一个词条的末尾加逗号。听写使用大括号"{...}"

1
2
3
4
5
6
7
8
dic1 = {
    'bug':'A broken piece of code that causes a program to stop functioning',
    'string':'A piece of text',
    'integer':'A whole number',
    'float':'A decimal number',
    'function':'A block of organized and clean code that performs a task/action',
    'syntax':'A set of rules that says how a program will be coded',      
    }